diff --git a/docs/usage.md b/docs/usage.md index 3a29bd70..e1b47e44 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -121,11 +121,11 @@ return $.response[200].header("x-coolness-level", 10).text("This is cool!")`. ### Request parameters -Most of the time, the server's response depends on input from various parts of the request, which are accessible through `$.path`, `$.query`, `$.header`, and `$.body`. The best way to explain is with an example: +Most of the time, the server's response depends on input from various parts of the request, which are accessible through `$.path`, `$.query`, `$.headers`, and `$.body`. The best way to explain is with an example: ```ts export const GET: HTTP_GET = ($) => { - if ($.header['x-token'] !== 'super-secret') { + if ($.headers['x-token'] !== 'super-secret') { return $.response[401].text('unauthorized'); } diff --git a/src/server/types.ts b/src/server/types.ts index 066ec344..20396880 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -259,7 +259,7 @@ interface WideResponseBuilder { interface WideOperationArgument { body: unknown; context: unknown; - header: { [key: string]: string }; + headers: { [key: string]: string }; path: { [key: string]: string }; proxy: (url: string) => { proxyUrl: string }; query: { [key: string]: string }; diff --git a/src/typescript-generator/operation-type-coder.js b/src/typescript-generator/operation-type-coder.js index ffe581ac..8f3fd984 100644 --- a/src/typescript-generator/operation-type-coder.js +++ b/src/typescript-generator/operation-type-coder.js @@ -110,7 +110,7 @@ export class OperationTypeCoder extends TypeCoder { const pathType = new ParametersTypeCoder(parameters, "path").write(script); - const headerType = new ParametersTypeCoder(parameters, "header").write( + const headersType = new ParametersTypeCoder(parameters, "header").write( script, ); @@ -139,7 +139,7 @@ export class OperationTypeCoder extends TypeCoder { const proxyType = "(url: string) => COUNTERFACT_RESPONSE"; - return `($: OmitValueWhenNever<{ query: ${queryType}, path: ${pathType}, header: ${headerType}, body: ${bodyType}, context: ${contextTypeImportName}, response: ${responseType}, x: ${xType}, proxy: ${proxyType}, user: ${this.userType()} }>) => ${this.responseTypes( + return `($: OmitValueWhenNever<{ query: ${queryType}, path: ${pathType}, headers: ${headersType}, body: ${bodyType}, context: ${contextTypeImportName}, response: ${responseType}, x: ${xType}, proxy: ${proxyType}, user: ${this.userType()} }>) => ${this.responseTypes( script, )} | { status: 415, contentType: "text/plain", body: string } | COUNTERFACT_RESPONSE | { ALL_REMAINING_HEADERS_ARE_OPTIONAL: COUNTERFACT_RESPONSE }`; }