-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…keeps-the-reference fixed deepPartial modifier preserving refId
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { z } from 'zod'; | ||
import { expectSchema, generateDataForRoute } from '../lib/helpers'; | ||
|
||
describe('describe', () => { | ||
it('generates a deepPartial object', () => { | ||
const schema = z.object({ | ||
a: z.string(), | ||
b: z.number(), | ||
}); | ||
|
||
const { requestBody } = generateDataForRoute({ | ||
request: { | ||
body: { | ||
description: 'Test description', | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: schema.deepPartial(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(requestBody).toEqual({ | ||
description: 'Test description', | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
a: { type: 'string' }, | ||
b: { type: 'number' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('generates a deepPartial object from a registered schema', () => { | ||
const schema = z | ||
.object({ | ||
a: z.string(), | ||
b: z.number(), | ||
}) | ||
.openapi('TestSchema'); | ||
|
||
const { documentSchemas, requestBody, responses } = generateDataForRoute({ | ||
request: { | ||
body: { | ||
description: 'Test description', | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: schema.deepPartial(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
200: { | ||
description: 'Response description', | ||
content: { | ||
'application/json': { schema }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// The schema is registered | ||
expect(documentSchemas).toEqual({ | ||
TestSchema: { | ||
type: 'object', | ||
properties: { | ||
a: { type: 'string' }, | ||
b: { type: 'number' }, | ||
}, | ||
required: ['a', 'b'], | ||
}, | ||
}); | ||
|
||
expect(responses[200]).toEqual({ | ||
description: 'Response description', | ||
content: { | ||
'application/json': { | ||
schema: { $ref: '#/components/schemas/TestSchema' }, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(requestBody).toEqual({ | ||
description: 'Test description', | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
a: { type: 'string' }, | ||
b: { type: 'number' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters