Skip to content

TypeError: Converting circular structure to JSON when interfaces are self-referenced or having circular dependencies #24

Description

@AshKemp23

@JaredCE The schema handler code in the plugin -> https://www.npmjs.com/package/serverless-openapi-documenter
uses this https://github.com/JaredCE/json-schema-to-openAPI-schema-object/blob/main/src/Convertor.js
where it fails in the constructor -> this.schema = JSON.parse(JSON.stringify(schema))

Can you please allow self-referencing models or circular dependencies without throwing an error?

Currently, it blocks document generation.

Let me provide you with more context on the error:
This is the error thrown ->
ERROR: An error was thrown generating the OpenAPI v3 documentation

Error:
ServerlessError: 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

I was checking your documenter plugin -> In this file openAPIGenerator.js it failed in this line.

await generator.parse()
.catch(err => {
this.log(ERROR: An error was thrown generating the OpenAPI v3 documentation, this.logTypes.ERROR)
throw new this.serverless.classes.Error(err)
})

Further -> in definitionGenerator.js

in parse function -> I suspect it fails in the following line:

await this.schemaHandler.addModelsToOpenAPI().catch((err) => {
throw err;
});

Further -> in schemaHandler.js -> I suspect it fails somewhere in the following block I think:

async __dereferenceSchema(schema) {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions