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

Multiple schemas resolved to the same name #297

Open
mbierma opened this issue Sep 12, 2023 · 1 comment
Open

Multiple schemas resolved to the same name #297

mbierma opened this issue Sep 12, 2023 · 1 comment

Comments

@mbierma
Copy link
Contributor

mbierma commented Sep 12, 2023

It's possible for multiple schemas to resolve to the same name. When this happens, one schema will mask the other, which results in invalid OpenAPI specifications. For example, if we have the following contrived schema:

class Parent(m.Schema):

    class ChildOne(m.Schema):
        class Two(m.Schema):
            test_child_one_two = m.fields.String()
        two = m.fields.Nested(Two)

    class ChildTwo(m.Schema):
        class Two(m.Schema):
            test_child_two_two = m.fields.String()
        two = m.fields.Nested(Two)

    test_child_one = m.fields.Nested(ChildOne)
    test_child_two = m.fields.Nested(ChildTwo)

This will generate the resulting definition:

{
  "Two": {
    "additionalProperties": false,
    "properties": {
      "test_child_two_two": {
        "type": "string"
      }
    },
    "title": "Two",
    "type": "object"
  },
  "ChildOne": {
    "additionalProperties": false,
    "properties": {
      "two": {
        "$ref": "#/definitions/Two"
      }
    },
    "title": "ChildOne",
    "type": "object"
  },
  "ChildTwo": {
    "additionalProperties": false,
    "properties": {
      "two": {
        "$ref": "#/definitions/Two"
      }
    },
    "title": "ChildTwo",
    "type": "object"
  },
  "Parent": {
    "additionalProperties": false,
    "properties": {
      "test_child_one": {
        "$ref": "#/definitions/ChildOne"
      },
      "test_child_two": {
        "$ref": "#/definitions/ChildTwo"
      }
    },
    "title": "Parent",
    "type": "object"
  }
}

However, we can see that the definition for Two contains one property:test_child_two_two, and test_child_one_two is missing. I'd expect either an exception, or a way to automatically generate a unique name, if the schema name is already in use. The latter is similar to what apispec uses.

In both normalize_schema and get_swagger_title, it seems difficult to determine if the name is unique, as they are lacking access to additional context.

Any feedback on the appropriate steps to resolve this within the rebar framework?

@mbierma
Copy link
Contributor Author

mbierma commented Sep 12, 2023

Perhaps it would be best to check the definition_.response_body_schema, definition_.query_string_schema, and definition_.request_body_schema in paths?

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