Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header params are missing or duplicated #1769

Merged
merged 8 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 176 additions & 1 deletion tests/unit/__snapshots__/documentation.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3683,7 +3683,7 @@ servers:
"
`;

exports[`Documentation > Feature 1180: Headers opt-in params > should describe x- inputs as header params 1`] = `
exports[`Documentation > Feature 1180: Headers opt-in params > should describe x- inputs as header params in get request 1`] = `
"openapi: 3.1.0
info:
title: Testing headers params
Expand Down Expand Up @@ -3763,6 +3763,181 @@ servers:
"
`;

exports[`Documentation > Feature 1180: Headers opt-in params > should describe x- inputs as header params in post request 1`] = `
"openapi: 3.1.0
info:
title: Testing headers params
version: 3.4.5
paths:
/v1/test:
post:
operationId: PostV1Test
parameters:
- name: id
in: query
required: true
description: POST /v1/test Parameter
schema:
type: string
- name: x-request-id
in: header
required: true
description: POST /v1/test Parameter
schema:
type: string
RobinTail marked this conversation as resolved.
Show resolved Hide resolved
requestBody:
description: POST /v1/test Request body
content:
application/json:
schema:
type: object
properties:
id:
type: string
x-request-id:
type: string
RobinTail marked this conversation as resolved.
Show resolved Hide resolved
required:
- id
- x-request-id
responses:
"200":
description: POST /v1/test Positive response
content:
application/json:
schema:
type: object
properties:
status:
type: string
const: success
data:
type: object
required:
- status
- data
"400":
description: POST /v1/test Negative response
content:
application/json:
schema:
type: object
properties:
status:
type: string
const: error
error:
type: object
properties:
message:
type: string
required:
- message
required:
- status
- error
examples:
example1:
value:
status: error
error:
message: Sample error message
components:
schemas: {}
responses: {}
parameters: {}
examples: {}
requestBodies: {}
headers: {}
securitySchemes: {}
links: {}
callbacks: {}
tags: []
servers:
- url: https://example.com
"
`;

exports[`Documentation > Feature 1180: Headers opt-in params > should describe x- inputs as header params in put request 1`] = `
"openapi: 3.1.0
info:
title: Testing headers params
version: 3.4.5
paths:
/v1/test:
put:
operationId: PutV1Test
requestBody:
description: PUT /v1/test Request body
content:
application/json:
schema:
type: object
properties:
id:
type: string
x-request-id:
type: string
RobinTail marked this conversation as resolved.
Show resolved Hide resolved
required:
- id
- x-request-id
responses:
"200":
description: PUT /v1/test Positive response
content:
application/json:
schema:
type: object
properties:
status:
type: string
const: success
data:
type: object
required:
- status
- data
"400":
description: PUT /v1/test Negative response
content:
application/json:
schema:
type: object
properties:
status:
type: string
const: error
error:
type: object
properties:
message:
type: string
required:
- message
required:
- status
- error
examples:
example1:
value:
status: error
error:
message: Sample error message
components:
schemas: {}
responses: {}
parameters: {}
examples: {}
requestBodies: {}
headers: {}
securitySchemes: {}
links: {}
callbacks: {}
tags: []
servers:
- url: https://example.com
"
`;

exports[`Documentation > Issue #98 > Should describe non-empty array 1`] = `
"openapi: 3.1.0
info:
Expand Down
49 changes: 28 additions & 21 deletions tests/unit/documentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,31 +981,38 @@ describe("Documentation", () => {
describe("Feature 1180: Headers opt-in params", () => {
const specificConfig = createConfig({
...sampleConfig,
inputSources: { get: ["query", "params", "headers"] },
inputSources: {
get: ["query", "params", "headers"],
post: ["body", "query", "params", "headers"],
put: ["body", "headers"], // query is not enabled
},
});

test("should describe x- inputs as header params", () => {
const spec = new Documentation({
config: specificConfig,
routing: {
v1: {
test: defaultEndpointsFactory.build({
method: "get",
input: z.object({
id: z.string(),
"x-request-id": z.string(),
test.each(["get", "post", "put"] as const)(
"should describe x- inputs as header params in %s request",
(method) => {
const spec = new Documentation({
config: specificConfig,
routing: {
v1: {
test: defaultEndpointsFactory.build({
method,
input: z.object({
id: z.string(),
"x-request-id": z.string(),
}),
output: z.object({}),
handler: vi.fn(),
}),
output: z.object({}),
handler: vi.fn(),
}),
},
},
},
version: "3.4.5",
title: "Testing headers params",
serverUrl: "https://example.com",
}).getSpecAsYaml();
expect(spec).toMatchSnapshot();
});
version: "3.4.5",
title: "Testing headers params",
serverUrl: "https://example.com",
}).getSpecAsYaml();
expect(spec).toMatchSnapshot();
},
);
});

describe("Feature #1431: Multiple schemas for different status codes", () => {
Expand Down