serverless-openapi-documenter icon indicating copy to clipboard operation
serverless-openapi-documenter copied to clipboard

[BUG] - Cannot generate openapi document for self-referencing interface or circular dependencies

Open AshKemp23 opened this issue 2 years ago • 1 comments

Describe the bug I get the following error when I try to generate an open API document for an interface that references itself or contains circular dependency with another interface.

Converting circular structure to JSON --> starting at object with constructor 'Object' | property 'properties' -> object with constructor 'Object' | property 'subRows' -> object with constructor 'Object' --- property 'items' closes the circle 400 ERROR >>>> TypeError: Converting circular structure to JSON --> starting at object with constructor 'Object' | property 'properties' -> object with constructor 'Object' | property 'subRows' -> object with constructor 'Object' --- property 'items' closes the circle at JSON.stringify ()

To Reproduce You can go ahead and reproduce this with the below schema as an example. Pass this schema to deferenceSchema function and use the dereferenced schema in the convert function. Here default_2 references itself in the subRows. Example provided below: const schema = { title: 'UserResponse', description: 'Response object for user', type: 'object', properties: { user: { $ref: '#/definitions/default_1', description: 'user details', }, }, definitions: { default_1: { type: 'object', properties: { id: { type: 'number', }, basicInformation: { type: 'object', properties: { firstName: { type: 'string', }, lastName: { type: 'string', }, email: { type: 'string', } }, }, classes: { type: 'array', items: { $ref: '#/definitions/default_2', }, }, }, }, default_2: { type: 'object', properties: { className: { type: 'string', }, details: { type: 'array', items: { $ref: '#/definitions/default_3', }, }, id: { type: 'number', }, parentId: { type: 'number', }, subRows: { type: 'array', items: { $ref: '#/definitions/default_2', }, } }, }, default_3: { type: 'object', properties: { id: { type: 'number', }, detailDesc: { type: 'string', }, detailType: { $ref: '#/definitions/default_4', } }, }, default_4: { type: 'object', properties: { detailTypeName: { type: 'string', }, detailCode: { type: 'string', }, id: { type: 'number', }, }, }, }, $schema: 'http://json-schema.org/draft-07/schema#', };


const deReferencedSchema = await dereferenceSchema(schema);
const convertedSchemas = SchemaFactory.convert(deReferencedSchema, 'UserResponse');

**Expected behavior**
It should generate the document even if the interface is self-referencing or has circular dependencies.

**Desktop (please complete the following information):**
 - Serverless version: [e.g. 3.34.0]
 - serverless-openapi-documenter version : 0.0.72

AshKemp23 avatar Sep 22 '23 12:09 AshKemp23

I have made improvements to circular references as of 0.0.91.

JaredCE avatar Dec 13 '23 10:12 JaredCE

Circular references are much more improved. I'm going to close this issue. Feel free to open a new issue if you're having a problem still

JaredCE avatar Jun 18 '24 09:06 JaredCE