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

fix: required of parent schema not considered in allOf #1570 #1659

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions packages/core/src/getters/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export const combineSchemas = ({
propName = propName + pascal(getNumberWord(acc.schemas.length + 1));
}

// the required fields in this schema need to be considered
// in the sub schema under the allOf key
if (separator === 'allOf') {
subSchema = {...subSchema, required: schema.required};
}

const resolvedValue = resolveObject({
schema: subSchema,
propName,
Expand Down
12 changes: 12 additions & 0 deletions tests/configs/react-query.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ export default defineConfig({
target: '../specifications/polymorphic.yaml',
},
},
polymorphicRequired: {
output: {
target: '../generated/react-query/polymorphic-required/endpoints.ts',
schemas: '../generated/react-query/polymorphic-required/model',
client: 'react-query',
mock: true,
headers: true,
},
input: {
target: '../specifications/polymorphic-required.yaml',
},
},
namedParameters: {
output: {
target: '../generated/react-query/named-parameters/endpoints.ts',
Expand Down
59 changes: 59 additions & 0 deletions tests/specifications/polymorphic-required.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
openapi: 3.0.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you merge the yaml of these test files?
I don't wanna separeate related tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I merged those two into the existing polymorphic.yaml file now

info:
title: API
version: V1
paths:
/demo:
get:
operationId: getPolymorphicRequiredResponse
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
oneOf:
- $ref: '#/components/schemas/DescendantOne'
- $ref: '#/components/schemas/DescendantTwo'
components:
schemas:
DescendantOne:
required:
- type
- count
type: object
allOf:
- $ref: '#/components/schemas/ParentType'
- type: object
properties:
value:
type: boolean
count:
type: integer
format: int32
otherCount:
type: integer
format: int32
DescendantTwo:
type: object
allOf:
- $ref: '#/components/schemas/ParentType'
- type: object
properties:
value:
type: string
ParentType:
type: object
required:
- key
properties:
key:
type: string
type:
type: string
enum:
- BOOLEAN
- STRING
discriminator:
propertyName: type
Loading