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

3.1.0 parsing of schemas containing const throws errors #1975

Closed
spacether opened this issue Sep 20, 2023 · 0 comments
Closed

3.1.0 parsing of schemas containing const throws errors #1975

spacether opened this issue Sep 20, 2023 · 0 comments

Comments

@spacether
Copy link
Contributor

spacether commented Sep 20, 2023

v3.1.0 parsing of a document that contains valid const values is incorrectly throwing errors

swagger-parser version: 2.1.1

For this spec:

openapi: 3.1.0
servers:
- url: https://someserver.com/v1
info:
  title: openapi 3.1.0 sample spec
  version: 0.0.1
  description: sample spec for testing openapi functionality, built from json schema
    tests for draft2020-12
tags: []
paths: {}
components:
  schemas:
    ConstValidation:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: 2
    ConstWithObject:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
        foo: bar
        baz: bax
    ConstWithArray:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
      - foo: bar
    ConstWithNull:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: null
    ConstWithFalseDoesNotMatch0:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
      - false
    ConstWithTrueDoesNotMatch1:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
      - true
    ConstWithAFalseDoesNotMatchA0:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
        a: false
    ConstWithATrueDoesNotMatchA1:
      $schema: https://json-schema.org/draft/2020-12/schema
      const:
        a: true
    ConstWith0DoesNotMatchOtherZeroLikeTypes:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: 0
    ConstWith1DoesNotMatchTrue:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: 1
    ConstWith20MatchesIntegerAndFloatTypes:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: -2.0
    ConstFloatAndIntegersAreEqualUpTo64BitRepresentationLimits:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: 9007199254740992
    ConstNulCharactersInStrings:
      $schema: https://json-schema.org/draft/2020-12/schema
      const: "hello\0there"

When parsing the document, these errors are incorrectly thrown:

 | Error count: 6, Warning count: 0
Errors: 
        -attribute components.schemas.ConstWithArray.const is not of type `string`
        -attribute components.schemas.ConstWithAFalseDoesNotMatchA0.const is not of type `string`
        -attribute components.schemas.ConstWithObject.const is not of type `string`
        -attribute components.schemas.ConstWithATrueDoesNotMatchA1.const is not of type `string`
        -attribute components.schemas.ConstWithFalseDoesNotMatch0.const is not of type `string`
        -attribute components.schemas.ConstWithTrueDoesNotMatch1.const is not of type `string`

This blocks compliance to json schema 2020-12, required by openapi v3.1.0
This came up when writing: openapi-json-schema-tools/openapi-json-schema-generator#241

Related:
#1966

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