Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions example/example.documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ paths:
type: object
properties:
status:
type: string
const: success
data:
type: object
Expand Down Expand Up @@ -57,6 +58,7 @@ paths:
type: object
properties:
status:
type: string
const: error
error:
type: object
Expand Down Expand Up @@ -174,6 +176,7 @@ paths:
type: object
properties:
status:
type: string
const: success
data:
type: object
Expand Down Expand Up @@ -211,6 +214,7 @@ paths:
type: object
properties:
status:
type: string
const: error
error:
type: object
Expand Down Expand Up @@ -255,6 +259,7 @@ paths:
type: object
properties:
status:
type: string
const: created
data:
type: object
Expand All @@ -275,6 +280,7 @@ paths:
type: object
properties:
status:
type: string
const: created
data:
type: object
Expand All @@ -295,6 +301,7 @@ paths:
type: object
properties:
status:
type: string
const: error
reason:
type: string
Expand All @@ -309,6 +316,7 @@ paths:
type: object
properties:
status:
type: string
const: exists
id:
type: integer
Expand All @@ -325,6 +333,7 @@ paths:
type: object
properties:
status:
type: string
const: error
reason:
type: string
Expand Down Expand Up @@ -455,6 +464,7 @@ paths:
type: object
properties:
status:
type: string
const: success
data:
type: object
Expand Down Expand Up @@ -490,6 +500,7 @@ paths:
type: object
properties:
status:
type: string
const: error
error:
type: object
Expand Down Expand Up @@ -529,6 +540,7 @@ paths:
type: object
properties:
status:
type: string
const: success
data:
type: object
Expand All @@ -549,6 +561,7 @@ paths:
type: object
properties:
status:
type: string
const: error
error:
type: object
Expand Down Expand Up @@ -593,6 +606,7 @@ paths:
type: integer
exclusiveMaximum: 9007199254740991
event:
type: string
const: time
id:
type: string
Expand Down Expand Up @@ -644,6 +658,7 @@ paths:
type: object
properties:
status:
type: string
const: success
data:
type: object
Expand All @@ -664,6 +679,7 @@ paths:
type: object
properties:
status:
type: string
const: error
error:
type: object
Expand Down
12 changes: 12 additions & 0 deletions express-zod-api/src/documentation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ export const depictNullable: Depicter = ({ jsonSchema }) => {
const isSupportedType = (subject: string): subject is SchemaObjectType =>
subject in samples;

export const depictEnum: Depicter = ({ jsonSchema }) => ({
type: typeof jsonSchema.enum?.[0],
...jsonSchema,
});

export const depictLiteral: Depicter = ({ jsonSchema }) => ({
type: typeof (jsonSchema.const || jsonSchema.enum?.[0]),
...jsonSchema,
});

const ensureCompliance = ({
$ref,
type,
Expand Down Expand Up @@ -450,6 +460,8 @@ const depicters: Partial<Record<FirstPartyKind | ProprietaryBrand, Depicter>> =
intersection: depictIntersection,
tuple: depictTuple,
pipe: depictPipeline,
literal: depictLiteral,
enum: depictEnum,
[ezDateInBrand]: depictDateIn,
[ezDateOutBrand]: depictDateOut,
[ezUploadBrand]: depictUpload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ exports[`Documentation helpers > depictDefault() > Feature #1706: should overrid
}
`;

exports[`Documentation helpers > depictEnum() > should set type 1`] = `
{
"enum": [
"test",
"jest",
],
"type": "string",
}
`;

exports[`Documentation helpers > depictExamples() > should 'pass' examples in case of 'request' 1`] = `
{
"example1": {
Expand Down Expand Up @@ -202,6 +212,23 @@ exports[`Documentation helpers > depictIntersection() > should merge examples de
}
`;

exports[`Documentation helpers > depictLiteral() > should set type from either const or enum prop 0 1`] = `
{
"const": "test",
"type": "string",
}
`;

exports[`Documentation helpers > depictLiteral() > should set type from either const or enum prop 1 1`] = `
{
"enum": [
"test",
"jest",
],
"type": "string",
}
`;

exports[`Documentation helpers > depictNullable() > should add null type to the first of anyOf 0 1`] = `
{
"type": [
Expand Down
Loading