Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AshKemp23 opened this issue Sep 22, 2023 · 2 comments
Assignees

Comments

@AshKemp23
Copy link

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
@JaredCE
Copy link
Owner

JaredCE commented Dec 13, 2023

I have made improvements to circular references as of 0.0.91.

@JaredCE
Copy link
Owner

JaredCE commented Jun 18, 2024

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 JaredCE closed this as completed Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants