diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 08380fa9e..cced8b669 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -94,12 +94,25 @@ export const resolveMockValue = ({ isRef: true, }; + const newSeparator = newSchema.allOf + ? 'allOf' + : newSchema.oneOf + ? 'oneOf' + : 'anyOf'; + const scalar = getMockScalar({ item: newSchema, mockOptions, operationId, tags, - combine, + combine: combine + ? { + separator: + combine.separator === 'anyOf' ? newSeparator : combine.separator, + includedProperties: + newSeparator === 'allOf' ? [] : combine.includedProperties, + } + : undefined, context: { ...context, specKey, @@ -147,6 +160,10 @@ export const resolveMockValue = ({ }); } + if (scalar.value && newSchema.allOf && combine?.separator === 'anyOf') { + scalar.value = `{${scalar.value}}`; + } + return { ...scalar, type: newSchema.type, diff --git a/tests/specifications/any-of.yaml b/tests/specifications/any-of.yaml index 46c70d99c..eec63f6ef 100644 --- a/tests/specifications/any-of.yaml +++ b/tests/specifications/any-of.yaml @@ -33,6 +33,17 @@ paths: application/json: schema: $ref: '#/components/schemas/Pet' + /any-of-included-all-of-and-shared-schema-pet: + get: + summary: Gets anyOf included allOf and shared schema pets + operationId: getAnyOfIncludedAllOfAndSharedSchemaPets + responses: + '200': + description: Pet + content: + application/json: + schema: + $ref: '#/components/schemas/CatDetail' components: schemas: A: @@ -68,3 +79,21 @@ components: properties: name: type: string + CatDetail: + type: object + required: + - detail + properties: + detail: + anyOf: + - $ref: '#/components/schemas/Cat' + - $ref: '#/components/schemas/CatExpandDetail' + CatExpandDetail: + allOf: + - $ref: '#/components/schemas/Cat' + - type: object + required: + - url + properties: + url: + type: string