swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

3.1.0 parsing of schema containing dependentRequired adds values not present in document

Open spacether opened this issue 2 years ago • 0 comments

3.1.0 parsing of schema containing dependentRequired adds values not present in spec

using swagger-parser v2.1.1 when parsing a spec with this schema:

    DependenciesWithEscapedCharacters:
      $schema: https://json-schema.org/draft/2020-12/schema
      dependentRequired:
        ? 'foo

          bar'
        : - "foo\rbar"
        foo"bar:
        - foo'bar

Swagger parser loads the dependentRequired map as:

{foo
bar=[foo
bar, foo'bar], foo"bar=[foo
bar, foo'bar]}

Where each key stores an array which incorrectly contains 2 values when it should contain only one.

Samples spec is here:

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:
    DependenciesWithEscapedCharacters:
      $schema: https://json-schema.org/draft/2020-12/schema
      dependentRequired:
        ? 'foo

          bar'
        : - "foo\rbar"
        foo"bar:
        - foo'bar

This prevents users of this library from correctly implementing dependentRequired.

This came up when writing: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/pull/241

spacether avatar Sep 23 '23 18:09 spacether