[BUG] - Cannot generate openapi document for self-referencing interface or circular dependencies
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
I have made improvements to circular references as of 0.0.91.
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