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

Fields takes precedence over types #469

Open
Zn4rK opened this issue Jul 4, 2022 · 0 comments
Open

Fields takes precedence over types #469

Zn4rK opened this issue Jul 4, 2022 · 0 comments

Comments

@Zn4rK
Copy link

Zn4rK commented Jul 4, 2022

Describe the bug

It seems to me like the fields in a schema takes precedence whenever a field references a type that already exists. For inline objects, it seems reasonable to generate the type name, but pure references should take priority - no?

To Reproduce
Use this schema:

{
  "info": {
    "title": "Test",
    "version": "0.0.0"
  },
  "openapi": "3.0.2",
  "paths": {
    "/user": {
      "get": {
        "description": "Doesn't matter",
        "tags": [
          "user"
        ],
        "responses": {
          "200": {
            "description": "A user",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "something": {
            "type": "string"
          },
          "thing": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Thing"
            }
          }
        }
      },
      "Thing": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    }
  }
}

And generate the schema. The end result will look like this:

type Query {
  user: User
}

type Thing2 {
  name: String
}

type User {
  something: String
  thing: [Thing2]
}

Expected behavior
I would expect the schema to look like this:

type Query {
  user: User
}

type Thing {
  name: String
}

type User {
  something: String
  thing: [Thing]
}

I.e it shouldn't create a new type since it has one specified in the component/schema section.

Additional context
I've tried to workaround this with various options, but to no avail. My solution as of right now is to do some pre-processing on the schema, and then fix it with schema wrapping.

I can probably identify and fix this bug if it's declared a bug.

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

1 participant