Skip to content

Commit 7db698e

Browse files
committed
additional test for examples of individual prop in a depicted body.
1 parent 62ba8a4 commit 7db698e

2 files changed

Lines changed: 127 additions & 27 deletions

File tree

express-zod-api/tests/__snapshots__/documentation.spec.ts.snap

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3850,7 +3850,7 @@ servers:
38503850
"
38513851
`;
38523852

3853-
exports[`Documentation > Metadata > should pass over the example of an individual parameter 1`] = `
3853+
exports[`Documentation > Metadata > should pass over the example of an individual prop in get request 1`] = `
38543854
"openapi: 3.1.0
38553855
info:
38563856
title: Testing Metadata:example on IO parameter
@@ -3944,6 +3944,102 @@ servers:
39443944
"
39453945
`;
39463946

3947+
exports[`Documentation > Metadata > should pass over the example of an individual prop in post request 1`] = `
3948+
"openapi: 3.1.0
3949+
info:
3950+
title: Testing Metadata:example on IO parameter
3951+
version: 3.4.5
3952+
paths:
3953+
/v1/getSomething:
3954+
post:
3955+
operationId: PostV1GetSomething
3956+
requestBody:
3957+
description: POST /v1/getSomething Request body
3958+
content:
3959+
application/json:
3960+
schema:
3961+
type: object
3962+
properties:
3963+
strNum:
3964+
examples:
3965+
- "123"
3966+
type: string
3967+
required:
3968+
- strNum
3969+
required: true
3970+
responses:
3971+
"200":
3972+
description: POST /v1/getSomething Positive response
3973+
content:
3974+
application/json:
3975+
schema:
3976+
type: object
3977+
properties:
3978+
status:
3979+
type: string
3980+
const: success
3981+
data:
3982+
type: object
3983+
properties:
3984+
numericStr:
3985+
examples:
3986+
- "456"
3987+
type: string
3988+
required:
3989+
- numericStr
3990+
examples:
3991+
- numericStr: "456"
3992+
required:
3993+
- status
3994+
- data
3995+
examples:
3996+
example1:
3997+
value:
3998+
status: success
3999+
data:
4000+
numericStr: "456"
4001+
"400":
4002+
description: POST /v1/getSomething Negative response
4003+
content:
4004+
application/json:
4005+
schema:
4006+
type: object
4007+
properties:
4008+
status:
4009+
type: string
4010+
const: error
4011+
error:
4012+
type: object
4013+
properties:
4014+
message:
4015+
type: string
4016+
required:
4017+
- message
4018+
required:
4019+
- status
4020+
- error
4021+
examples:
4022+
example1:
4023+
value:
4024+
status: error
4025+
error:
4026+
message: Sample error message
4027+
components:
4028+
schemas: {}
4029+
responses: {}
4030+
parameters: {}
4031+
examples: {}
4032+
requestBodies: {}
4033+
headers: {}
4034+
securitySchemes: {}
4035+
links: {}
4036+
callbacks: {}
4037+
tags: []
4038+
servers:
4039+
- url: https://example.com
4040+
"
4041+
`;
4042+
39474043
exports[`Documentation > Metadata > should pass over the schema description 1`] = `
39484044
"openapi: 3.1.0
39494045
info:

express-zod-api/tests/documentation.spec.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,34 +1025,38 @@ describe("Documentation", () => {
10251025
expect(spec).toMatchSnapshot();
10261026
});
10271027

1028-
test("should pass over the example of an individual parameter", () => {
1029-
const spec = new Documentation({
1030-
config: sampleConfig,
1031-
routing: {
1032-
v1: {
1033-
getSomething: defaultEndpointsFactory.build({
1034-
input: z.object({
1035-
strNum: z
1036-
.string()
1037-
.example("123") // example for the input side of the transformation
1038-
.transform((v) => parseInt(v, 10)),
1039-
}),
1040-
output: z.object({
1041-
numericStr: z
1042-
.number()
1043-
.transform((v) => `${v}`)
1044-
.example("456"), // example for the output side of the transformation
1028+
test.each<Method>(["get", "post"])(
1029+
"should pass over the example of an individual prop in %s request",
1030+
(method) => {
1031+
const spec = new Documentation({
1032+
config: sampleConfig,
1033+
routing: {
1034+
v1: {
1035+
getSomething: defaultEndpointsFactory.build({
1036+
method,
1037+
input: z.object({
1038+
strNum: z
1039+
.string()
1040+
.example("123") // example for the input side of the transformation
1041+
.transform((v) => parseInt(v, 10)),
1042+
}),
1043+
output: z.object({
1044+
numericStr: z
1045+
.number()
1046+
.transform((v) => `${v}`)
1047+
.example("456"), // example for the output side of the transformation
1048+
}),
1049+
handler: async () => ({ numericStr: 123 }),
10451050
}),
1046-
handler: async () => ({ numericStr: 123 }),
1047-
}),
1051+
},
10481052
},
1049-
},
1050-
version: "3.4.5",
1051-
title: "Testing Metadata:example on IO parameter",
1052-
serverUrl: "https://example.com",
1053-
}).getSpecAsYaml();
1054-
expect(spec).toMatchSnapshot();
1055-
});
1053+
version: "3.4.5",
1054+
title: "Testing Metadata:example on IO parameter",
1055+
serverUrl: "https://example.com",
1056+
}).getSpecAsYaml();
1057+
expect(spec).toMatchSnapshot();
1058+
},
1059+
);
10561060

10571061
test.each<Method>(["get", "post"])(
10581062
"should pass over examples of each param from the whole IO schema examples (%s method)",

0 commit comments

Comments
 (0)