Skip to content

False positive diff change when example used #814

@cinnes

Description

@cinnes

openapi-diff will incorrectly report a diff between two specs if example is used. Here's an example:

openapi: 3.0.1
info:
  title: My API
  version: 1.0.0
paths:
  /api/v1/csv:
    get:
      operationId: someCsvEndpoint
      responses:
        "200":
          content:
            text/csv:
              schema:
                type: string
                format: binary
                example: Example
          description: Successful operation
      security:
      - Bearer: []
      summary: Download a CSV or something
components:
  securitySchemes:
    Bearer:
      bearerFormat: JWT
      scheme: bearer
      type: http

Then:

➜ docker run --rm -it \
  -v "$(pwd):/specs" \
  openapitools/openapi-diff:2.1.2 \
  /specs/myspec.yaml /specs/myspec.yaml
==========================================================================
==                            API CHANGE LOG                            ==
==========================================================================
                                  My API
--------------------------------------------------------------------------
--                            What's Changed                            --
--------------------------------------------------------------------------
- GET    /api/v1/csv
  Return Type:
    - Changed 200 OK
      Media types:
        - Changed text/csv
          Schema: Backward compatible
--------------------------------------------------------------------------
--                                Result                                --
--------------------------------------------------------------------------
                   API changes are backward compatible
--------------------------------------------------------------------------

Comparing it against itself detects a change. Removing example entirely:

openapi: 3.0.1
info:
  title: My API
  version: 1.0.0
paths:
  /api/v1/csv:
    get:
      operationId: someCsvEndpoint
      responses:
        "200":
          content:
            text/csv:
              schema:
                type: string
                format: binary
          description: Successful operation
      security:
      - Bearer: []
      summary: Download a CSV or something
components:
  securitySchemes:
    Bearer:
      bearerFormat: JWT
      scheme: bearer
      type: http

and...

➜ docker run --rm -it \
  -v "$(pwd):/specs" \
  openapitools/openapi-diff:2.1.2 \
  /specs/myspec.yaml /specs/myspec.yaml
No differences. Specifications are equivalents

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions