Skip to content

Circular references #64

@slinkydeveloper

Description

@slinkydeveloper

It seems that loading an api spec with schemas with circular references causes the parse() method throws StackOverflowException.

Steps to reproduce

Try to load this spec:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: bundle schema test
paths:
  /pets:
    get:
      operationId: findPets
      responses:
        200:
          description: "hello"
components:
  schemas:
    schema1:
      title: schema1
      type: object
      properties:
        a:
          $ref: '#/components/schemas/schema2'
        b:
          type: string
        c:
          type: number
    schema2:
      title: schema2
      type: object
      properties:
        a:
          type: array
          items:
            $ref: '#/components/schemas/schema1'

Some investigation

I've done some investigation to try to fix that bug. It can be resolved processing the references nodes during the spec walk.
For example: in the spec above when you call parse() the parser doesn't have to resolve the schema1.properties.a reference, because it goes on StackOverflowException. If you call model....get("a") It has to solve the reference and give me a SchemaImpl object. Then, the next time you call model....get("a"), the reference is already solved.
Of course it decreases a little bit the perfomances but I think it can be enabled/disabled with a flag during parser initialization

I tried to fix it 😃

I tried to fix it, but I haven't understand some code. Sorry for that, I attach my progresses: circular-reference.zip (this patch is referenced to branch master of my fork). Inspecting the code, it seems that after trying to walk into a JsonOverlay of a reference, it has the right json deferenced but it doesn't have values (in the BundleSchemaTest you can look that model.getSchemas().get("schema2").getProperties().get("a").getTitle() returns null, try to inspect it). Also I think that my attempt to fix it fails on ObjectOverlay#fromJson() function.

Also in this code there's a function inside SchemaImpl called bundleSchema(). This is a small draft attempting to replicate this functionality (I need the schema to validate requests for my vertx-web project). Of course I can't test it because parser doesn't load the project

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions