chore: fix circular crash

Co-authored-by: Alex Varchuk <olexandr.varchuk@gmail.com>
This commit is contained in:
Roman Hotsiy 2022-08-08 16:47:56 -05:00 committed by Alex Varchuk
parent cfd810fdf9
commit 87c79916df
2 changed files with 42 additions and 2 deletions

View File

@ -555,5 +555,45 @@ describe('Models', () => {
packSize: <integer>
`);
});
test('should detect and recursion with nested oneOf', () => {
const spec = parseYaml(outdent`
openapi: 3.0.0
components:
schemas:
Tag:
type: object
properties:
name:
description: Tag name
type: string
minLength: 1
items:
oneOf:
- $ref: "#/components/schemas/Tag"
User:
type: object
properties:
pet:
oneOf:
- $ref: '#/components/schemas/Tag'
`) 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
Tag ->
name: <string> (Tag name)
items: oneOf
Tag -> <object> !circular
`);
});
});
});

View File

@ -254,10 +254,10 @@ export class SchemaModel {
title,
allOf: [{ ...this.schema, oneOf: undefined, anyOf: undefined }],
} as OpenAPISchema,
this.pointer + '/oneOf/' + idx,
variant.$ref || this.pointer + '/oneOf/' + idx,
this.options,
false,
this.refsStack,
refsStack,
);
return schema;