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

[BUG] Reusable enums cause error #9

Closed
lorissikora opened this issue Feb 2, 2023 · 1 comment
Closed

[BUG] Reusable enums cause error #9

lorissikora opened this issue Feb 2, 2023 · 1 comment

Comments

@lorissikora
Copy link
Contributor

lorissikora commented Feb 2, 2023

When defining an enum within the components/schemas section of the openapi schema, it results in a crash. One would do this as to reuse the enum or simply return an array of enum values inside a property. The reason for this crash is the following:

Given is the following schema:

openapi: 3.0.3
components:
  schemas:
    Example:
      type: object
      properties:
        nestedEnum:
          type: string
          enum:
            - A
            - B
            - C
    Fruit:
      type: string
      enum:
        - Apple
        - Orange
        - Pear

We have a nestedEnum which is defined within an additional schema, while the Fruit enum itself is a top-level schema. This will produce the following resolved definitions:

{
  'ExampleNestedEnum#EnumTypeSuffix': [ 'A', 'B', 'C' ],
  Example: { 'nestedEnum?': 'ExampleNestedEnum#EnumTypeSuffix' },
  'FruitFruit#EnumTypeSuffix': [ 'Apple', 'Orange', 'Pear' ],
  Fruit: 'FruitFruit#EnumTypeSuffix'
}

The problem here, I believe, is that Fruit is a schema and as such causes not only the FruitFruit#EnumTypeSuffix to be created, but also itself gets inserted as a regular schema into the resolved definitions. This is done by the DefinitionsResolver regardless of the type of schema. This later on causes an error when the resolver fails to do so. In addition to this, there seems to be a naming issue in this circumstance, as seen by the name FruitFruit#EnumTypeSuffix which results in an enum named FruitFruit.

I have formulated my proposed changes in a PR #8

@teobler
Copy link
Owner

teobler commented Feb 7, 2023

Thanks very much @lorissikora for fixing this issue, will close this

@teobler teobler closed this as completed Feb 7, 2023
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