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

dereference output depends on order of input schemas #67

Open
jayvdb opened this issue Jan 18, 2023 · 1 comment
Open

dereference output depends on order of input schemas #67

jayvdb opened this issue Jan 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@jayvdb
Copy link
Collaborator

jayvdb commented Jan 18, 2023

We have a bunch of schemas being included from external files.

If a schema refers to a schema that appears after it, like this, the result is very different ...

    SchemaDUsingC:
      $ref: "./schemas/SchemaDUsingC.yaml#/components/schemas/SchemaDUsingC"
    SchemaA:
      $ref: "./schemas/SchemaA.yaml#/components/schemas/SchemaA"
    SchemaBUsingA:
      $ref: "./schemas/SchemaBUsingA.yaml#/components/schemas/SchemaBUsingA"
    SchemaCUsingB:
      $ref: "./schemas/SchemaCUsingB.yaml#/components/schemas/SchemaCUsingB"

... to when the schemas are ordered so they always only include prior schemas, like:

    SchemaA:
      $ref: "./schemas/SchemaA.yaml#/components/schemas/SchemaA"
    SchemaBUsingA:
      $ref: "./schemas/SchemaBUsingA.yaml#/components/schemas/SchemaBUsingA"
    SchemaCUsingB:
      $ref: "./schemas/SchemaCUsingB.yaml#/components/schemas/SchemaCUsingB"
    SchemaDUsingC:
      $ref: "./schemas/SchemaDUsingC.yaml#/components/schemas/SchemaDUsingC"

I can provide more details of the schemas if that helps, and reduce it to a few schemas only to better demonstrate the problem.
We're able to workaround it by carefully ordering the schemas.

@kstasik
Copy link
Owner

kstasik commented Jan 18, 2023

You are right. Currently you have to provide all schemas in OpenApi document starting from the most simple:
https://github.com/kstasik/schema-tools-templates/blob/master/tests/rust/spec/api/api.yaml#L16

I was thinking about rebuilding it. Instead of generating names on demand during recursive iteration program would have to gather flat structure of entities with suggested names and relations (for example parent schema reference). Sort them by putting simple structures at the top and then starting the naming process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants