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

Add option to enable circular reference #154

Open
VolodymyrMachekhin opened this issue Feb 12, 2024 · 2 comments
Open

Add option to enable circular reference #154

VolodymyrMachekhin opened this issue Feb 12, 2024 · 2 comments

Comments

@VolodymyrMachekhin
Copy link

Hello team! Thank you again for creating and maintaining the library.
I have a question about the circular references. When I try to use a circular reference in spec it throws an error during the initialization.

ReferenceError: Circular $ref pointer found at...

The error is thrown by json-schema-ref-parser
While json-schema-ref-parser allows the circular refs, in the source code I found that oas-chow-chow puts a hardcoded option to the parser

dereference: {
  circular: false,
},

Is there any specific reason to it, and can it be changed?

@supertong
Copy link
Collaborator

Hey @VolodymyrMachekhin , AJV doesn't support circular reference for security reasons. You can find it here.

@VolodymyrMachekhin
Copy link
Author

Thank you @supertong for the reply. I found this in their documentation, and managed to modify chow-chow to compile the schema with circular reference.

if in chow-chow index we modify the ref parser call to parse schema without dereferencing

  public static async create(
    document: object,
    options: Partial<ChowOptions> = {}
  ) {
    const res = await $RefParser.parse(document, {
      continueOnError: false,
      resolve: {
        external: false,
      },
    });
    return new ChowChow(res as OpenAPIObject, options);
  }

and inside CompileSchema.ts before this.validator = ajvInstance.compile(schemaObject); is called the schema object is provided with components from await $RefParser.parse(document, {... then it compiles and works.

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