Skip to content

Commit

Permalink
type fix: header should be headers (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Jan 16, 2025
1 parent b4185ba commit c8606b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
4 changes: 2 additions & 2 deletions src/typescript-generator/operation-type-coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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 }`;
}
Expand Down

0 comments on commit c8606b5

Please sign in to comment.