Skip to content

OpenAPI 3.0.x Example Object lint rule: mutually exclusive doesn't always trigger #2141

@tim-lai

Description

@tim-lai

Q&A (please complete the following information)

  • ApiDOM version: v0.50.0
  • Swagger/OpenAPI version: OpenAPI 3.1.0, OpenAPI 3.0.x

Describe the bug you're encountering

There exists a linter rule at openapi/example/lint/value--mutually-exclusive.ts, which is in support the Example Object documentation: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object. However, the linter rule appears to only apply if one of the elements is an object, even if the specification allows for type Any.

To reproduce...

Try these examples at editor-next.swagger.io:

element value is an object (returns expected lint error):

openapi: 3.1.0
info: 
  title: deref
  version: 1.0.0
  license:
    name: Apache 2.0
    identifier: Apache-2.0
    url: http://should.not.exist.with.identifier.com
  
paths:
  /a:
    get:
      operationId: aget
      responses:
        '200':
          content: 
            application/json:
              schema:
                type: object
              examples:
                confirmation-success:
                  summary: short confirmation success                  
                  value:
                    option1: 'choice:one'
                    option2: 'choice:two'
                  externalValue: outsideLink

element value is an array (should have lint error):

openapi: 3.1.0
info: 
  title: deref
  version: 1.0.0
  license:
    name: Apache 2.0
    identifier: Apache-2.0
    url: http://should.not.exist.with.identifier.com
  
paths:
  /a:
    get:
      operationId: aget
      responses:
        '200':
          content: 
            application/json:
              schema:
                type: object
              examples:
                confirmation-success:
                  summary: short confirmation success                  
                  # value: confirmation-apple
                  value:
                    - choice:one
                    - choice:two
                  externalValue: outsideLink

element value is a string (should have lint error):

openapi: 3.1.0
info: 
  title: deref
  version: 1.0.0
  license:
    name: Apache 2.0
    identifier: Apache-2.0
    url: http://should.not.exist.with.identifier.com
  
paths:
  /a:
    get:
      operationId: aget
      responses:
        '200':
          content: 
            application/json:
              schema:
                type: object
              examples:
                confirmation-success:
                  summary: short confirmation success                  
                  value: confirmation-apple
                  externalValue: outsideLink

Expected behavior

The examples for array and string should yield lint error on element confirmation-success.

Screenshots

Additional context or thoughts

In the OpenAPI 3.1.0 case, the provided samples should also return a lint error on the License Object. The identifier and url both are not array or object types. This would be a separate lint rule.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions