Skip to content

3.1.0 Boolean schemas are silently omitted or cause parsing errors #1770

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

Open
spacether opened this issue Jul 10, 2022 · 1 comment
Open

Comments

@spacether
Copy link
Contributor

spacether commented Jul 10, 2022

Boolean schemas (schemas where the value is true/false) are silently omitted or cause parsing errors

Swagger-parser version: 2.1.16

Sample spec:

openapi: 3.1.0
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /person/display/{personId}:
    get:
      parameters:
        - name: personId
          in: path
          required: true
          description: The id of the person to retrieve
          schema:
            type: string
      operationId: list
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BooleanTrue"
components:
  schemas:
    BooleanTrue: true
    ArrayWithTrueItems:
      type: array
      items: true
    ObjectWithTrueProperty:
      properties:
        someProp: true
    ObjectWithTrueAdditionalProperties:
      additionalProperties: true
    AllOfWithTrue:
      allOf:
        - true
    AnyOfWithTrue:
      anyOf:
        - true
    OneOfWithTrue:
      oneOf:
        - true
    NotWithTrue:
      not: true
    UnevaluatedItemsTrue:
      unevaluatedItems: true
    UnevaluatedPropertiesTrue:
      unevaluatedProperties: true
    PrefixitemsWithNoAdditionalItemsAllowed:
      $schema: https://json-schema.org/draft/2020-12/schema
      prefixItems:
      - {}
      - {}
      - {}
      items: false
    PrefixitemsWithBooleanSchemas:
      $schema: https://json-schema.org/draft/2020-12/schema
      prefixItems:
      - true
      - false

For these schemas, the booleans are not stored correctly or are omitted or a parser error is raised:

  • BooleanTrue
  • ArrayWithTrueItems
  • ObjectWithTrueProperty
  • AllOfWithTrue
  • AnyOfWithTrue
  • OneOfWithTrue
  • NotWithTrue
  • UnevaluatedItemsTrue
  • UnevaluatedPropertiesTrue
  • PrefixitemsWithNoAdditionalItemsAllowed
  • PrefixitemsWithBooleanSchemas

Note: contains: true works and does not have this bug

This issue is the biggest contributor to 3.1.0 json schema test suite failures

I am working on adding 3.1.0 features to my code generation project at https://github.com/openapi-json-schema-tools/openapi-json-schema-generator and I use your parser.
One way that I am verifying that my 3.1.0 json schema features are implemented correctly is by running the json schema test suite against my implementation.
Bugs in swagger-parser require me to skip certain tests because the parser is omitting or incorrectly processing document data. Of all those bugs, this one blocks the largest number of json schema tests.
Per this PR I count >= 85 test schemas that are excluded by boolean schemas not being processed correctly. This could easily be > 170 tests that are skipped because each test schema can have n tests running against it.

@spacether spacether changed the title Boolean schemas in allof are silently omitted Boolean schemas are silently omitted Aug 18, 2023
@spacether spacether changed the title Boolean schemas are silently omitted 3.1.0 Boolean schemas are silently omitted Aug 21, 2023
@spacether spacether changed the title 3.1.0 Boolean schemas are silently omitted 3.1.0 Boolean schemas are silently omitted or cause parsing errors Aug 30, 2023
@spacether
Copy link
Contributor Author

spacether commented Sep 27, 2023

@gracekarina @frantuma what kind of solution would you prefer here?

How would you want this addressed?
It looks like the most correct solution would be to change the return types to be Object like getAdditionalProperties does and that would be a breaking change.
Would you prefer something else like getNot remains unchanged and new getters are added like get310Not returns Object?

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