Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Schema type incorrectly set when omitted and enums given #1761

Closed
spacether opened this issue Jun 26, 2022 · 2 comments
Closed

Schema type incorrectly set when omitted and enums given #1761

spacether opened this issue Jun 26, 2022 · 2 comments

Comments

@spacether
Copy link
Contributor

spacether commented Jun 26, 2022

Schema type incorrectly set when omitted and enums given

Swagger-parser version: 2.0.31

Sample spec:

openapi: 3.0.3
info:
  title: openapi 3.0.3 sample spec
  description: sample spec for testing openapi functionality, built from json schema
    tests for draft6
  version: 0.0.1
paths: {}
components:
  schemas:
    SimpleEnumValidation:
      enum:
      - 1
      - 2
      - 3
    HeterogeneousEnumValidation:
      enum:
      - 6
      - foo
      - []
      - true
      - foo: 12
    HeterogeneousEnumWithNullValidation:
      enum:
      - 6
      - null
    EnumWithEscapedCharacters:
      enum:
      - 'foo

        bar'
      - "foo\rbar"
    EnumWithFalseDoesNotMatch0:
      enum:
      - false
    EnumWithTrueDoesNotMatch1:
      enum:
      - true
    EnumWith0DoesNotMatchFalse:
      enum:
      - 0
    EnumWith1DoesNotMatchTrue:
      enum:
      - 1
    NulCharactersInStrings:
      enum:
      - "hello\0there"

When parsing the above schema, type should be unset on all components
When one checks

  • SimpleEnumValidation, the parser incorrectly set type to number when it should remain unset.
  • HeterogeneousEnumValidation, the parser incorrectly sets the type to number when it should remain unset
  • This issue applies to all other components except for EnumsInProperties which correctly has type set to object
@spacether
Copy link
Contributor Author

This bug prevents spec writers from making enums with any type (unset type)

@frantuma
Copy link
Member

frantuma commented Jul 5, 2022

This has been fixed in #1768 with usage of new inferSchemaType option. By setting it to false type will not be anymore inferred

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants