Skip to content

Commit fa8dd6f

Browse files
committed
Adjusting implementation to keep type first and preserving most snapshots.
1 parent 10c23a9 commit fa8dd6f

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

example/example.documentation.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ paths:
1616
required: true
1717
description: a numeric string containing the id of the user
1818
schema:
19-
description: a numeric string containing the id of the user
2019
type: string
20+
description: a numeric string containing the id of the user
2121
format: regex
2222
pattern: \d+
2323
responses:
@@ -85,8 +85,8 @@ paths:
8585
required: true
8686
description: numeric string
8787
schema:
88-
description: numeric string
8988
type: string
89+
description: numeric string
9090
format: regex
9191
pattern: \d+
9292
responses:
@@ -578,9 +578,9 @@ paths:
578578
required: false
579579
description: for testing error response
580580
schema:
581+
type: string
581582
deprecated: true
582583
description: for testing error response
583-
type: string
584584
responses:
585585
"200":
586586
description: GET /v1/events/stream Positive response

express-zod-api/src/documentation-helpers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,19 @@ const ensureCompliance = ({
211211
...rest
212212
}: JSONSchema.BaseSchema): SchemaObject | ReferenceObject => {
213213
if ($ref) return { $ref };
214-
return {
214+
const valid: SchemaObject = {
215215
type: Array.isArray(type)
216216
? type.filter(isSupportedType)
217217
: type && isSupportedType(type)
218218
? type
219219
: undefined,
220-
allOf: allOf && allOf.map(ensureCompliance),
221-
oneOf: oneOf && oneOf.map(ensureCompliance),
222-
anyOf: anyOf && anyOf.map(ensureCompliance),
223-
not: not && ensureCompliance(not),
224220
...rest,
225221
};
222+
if (allOf) valid.allOf = allOf.map(ensureCompliance);
223+
if (oneOf) valid.oneOf = oneOf.map(ensureCompliance);
224+
if (anyOf) valid.anyOf = anyOf.map(ensureCompliance);
225+
if (not) valid.not = ensureCompliance(not);
226+
return valid;
226227
};
227228

228229
export const onDateIn: Overrider = ({ jsonSchema }, ctx) => {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ paths:
610610
required: true
611611
description: GET /v1/getSomething Parameter
612612
schema:
613+
type: array
613614
minItems: 1
614615
maxItems: 3
615-
type: array
616616
items:
617617
type: integer
618618
exclusiveMaximum: 9007199254740991
@@ -708,6 +708,8 @@ paths:
708708
content:
709709
application/json:
710710
schema:
711+
discriminator:
712+
propertyName: type
711713
anyOf:
712714
- type: object
713715
properties:
@@ -727,8 +729,6 @@ paths:
727729
required:
728730
- type
729731
- b
730-
discriminator:
731-
propertyName: type
732732
required: true
733733
responses:
734734
"200":
@@ -2405,8 +2405,8 @@ paths:
24052405
required: true
24062406
description: YYYY-MM-DDTHH:mm:ss.sssZ
24072407
schema:
2408-
description: YYYY-MM-DDTHH:mm:ss.sssZ
24092408
type: string
2409+
description: YYYY-MM-DDTHH:mm:ss.sssZ
24102410
format: date-time
24112411
pattern: ^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?)?Z?$
24122412
externalDocs:
@@ -2818,8 +2818,8 @@ paths:
28182818
required: true
28192819
description: GET /v1/getSomething Parameter
28202820
schema:
2821-
minItems: 1
28222821
type: array
2822+
minItems: 1
28232823
items:
28242824
type: string
28252825
responses:
@@ -3076,8 +3076,8 @@ paths:
30763076
required: true
30773077
description: GET /v1/getSomething Parameter
30783078
schema:
3079-
deprecated: true
30803079
type: string
3080+
deprecated: true
30813081
responses:
30823082
"200":
30833083
description: GET /v1/getSomething Positive response
@@ -3282,9 +3282,9 @@ paths:
32823282
components:
32833283
schemas:
32843284
GetHrisEmployeesParameterCursor:
3285+
type: string
32853286
description: An optional cursor string used for pagination. This can be
32863287
retrieved from the \`next\` property of the previous page response.
3287-
type: string
32883288
GetHrisEmployeesPositiveResponse:
32893289
type: object
32903290
properties:
@@ -3706,8 +3706,8 @@ paths:
37063706
required: true
37073707
description: here is the test
37083708
schema:
3709-
description: here is the test
37103709
type: string
3710+
description: here is the test
37113711
responses:
37123712
"200":
37133713
description: GET /v1/getSomething Positive response

0 commit comments

Comments
 (0)