From f7be345c0696ed7b84f1c3ad4fed1ec62e8cd284 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 7 Jul 2022 16:30:53 +0300 Subject: [PATCH] chore: add more test --- .../__tests__/models/Schema.circular.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/services/__tests__/models/Schema.circular.test.ts b/src/services/__tests__/models/Schema.circular.test.ts index 11f40127..043fb74b 100644 --- a/src/services/__tests__/models/Schema.circular.test.ts +++ b/src/services/__tests__/models/Schema.circular.test.ts @@ -482,5 +482,78 @@ describe('Models', () => { ] `); }); + + test('should detect and recursion with discriminator and oneOf', () => { + const spec = parseYaml(outdent` + openapi: 3.0.0 + components: + schemas: + User: + type: object + properties: + pet: + oneOf: + - $ref: '#/components/schemas/Pet' + Pet: + type: object + required: [ petType ] + discriminator: + propertyName: petType + mapping: + cat: '#/components/schemas/Cat' + dog: '#/components/schemas/Dog' + properties: + category: { $ref: '#/components/schemas/Category' } + status: { type: string } + friend: + allOf: [{ $ref: '#/components/schemas/Pet' }] + petType: { type: string } + Cat: + description: A representation of a cat + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + huntingSkill: { type: string } + Dog: + description: A representation of a dog + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + packSize: { type: integer } + Category: + type: object + properties: + name: { type: string } + `) as any; + + parser = new OpenAPIParser(spec, undefined, opts); + const schema = new SchemaModel( + parser, + spec.components.schemas.User, + '#/components/schemas/User', + opts, + ); + + expect(printSchema(schema, circularDetailsPrinter)).toMatchInlineSnapshot(` + pet: oneOf + Pet -> oneOf + cat -> + category: + name: + status: + friend: !circular + petType*: + huntingSkill: + dog -> + category: + name: + status: + friend: !circular + petType*: + packSize: + `); + }); }); });