diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index a5c793751..3f0efd792 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -152,9 +152,25 @@ export const combineSchemasMock = ({ return `${acc}${currentValue}${!combine ? '])' : ''}`; } + if (currentValue === '{}') { + currentValue = ''; + + if (acc.toString().endsWith(',')) { + acc = acc.toString().slice(0, -1); + } + } + return `${acc}${currentValue}${isObjectBounds ? '}' : ''}`; } + if (currentValue === '{}') { + currentValue = ''; + + if (acc.toString().endsWith(',')) { + acc = acc.toString().slice(0, -1); + } + } + if (!currentValue) { return acc; } diff --git a/tests/configs/default.config.ts b/tests/configs/default.config.ts index 1f1cb8ed7..69823cac2 100644 --- a/tests/configs/default.config.ts +++ b/tests/configs/default.config.ts @@ -105,6 +105,14 @@ export default defineConfig({ mock: true, }, }, + 'all-of': { + input: '../specifications/all-of.yaml', + output: { + schemas: '../generated/default/all-of/model', + target: '../generated/default/all-of/endpoints.ts', + mock: true, + }, + }, 'deeply-nested-refs': { input: '../specifications/deeply-nested-refs.yaml', output: { diff --git a/tests/specifications/all-of.yaml b/tests/specifications/all-of.yaml new file mode 100644 index 000000000..ff726cda2 --- /dev/null +++ b/tests/specifications/all-of.yaml @@ -0,0 +1,50 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: AnyOf Schema + license: + name: MIT +paths: + /not-has-properties-with-all-of-pets: + get: + operationId: getNotHasPropertiesWithAllOfPets + tags: + - pets + description: |- + Not has properties with allOf pets. + responses: + '200': + description: User + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Pet' + - $ref: '#/components/schemas/PetDetail' + - type: object + required: + - category + - type: object + required: + - color + +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + PetDetail: + type: object + required: + - tag + properties: + tag: + type: string