Tufin / oasdiff

OpenAPI Diff and Breaking Changes
https://www.oasdiff.com
Apache License 2.0
663 stars 59 forks source link

Incorrect Detection of Breaking Change for Default Values #549

Closed Krzysztof-Kolodziejczyk closed 2 months ago

Krzysztof-Kolodziejczyk commented 2 months ago

Incorrect Detection of Breaking Change for Default Values in oasdiff

Description

The oasdiff tool is incorrectly marking the addition of a new required property with a default value in request bodies as a breaking change. According to OpenAPI specifications, if a new required field in the request body schema is assigned a default value, it should not be considered a breaking change because it does not require any changes from the client’s side to maintain compatibility.

Versions

Steps to Reproduce

  1. OpenAPI Specification File 1.1 (api-1.1.yaml):

    
    openapi: 3.0.0
    info:
     title: Order API
     version: '1.1'
    paths:
     /order:
       post:
         summary: Create a new order
         requestBody:
           required: true
           content:
             application/json:
               schema:
                 $ref: '#/components/schemas/Order'
         responses:
           '200':
             description: Order created
    components:
     schemas:
       Order:
         type: object
         properties:
           itemId:
             type: string
  2. OpenAPI Specification File 1.2 (api-1.2.yaml):

    openapi: 3.0.0
    info:
    title: Order API
    version: '1.2'
    paths:
    /order:
    post:
      summary: Create a new order
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Order'
      responses:
        '200':
          description: Order created
    components:
    schemas:
    Order:
      type: object
      properties:
        itemId:
          type: string
        quantity:
          type: number
          default: 0
      required:
        - quantity
  3. Run oasdiff on these files: Use the following command to compare the two versions of the API specifications:

    oasdiff api-1.1.yaml api-1.2.yaml
  4. Output

    
    1 breaking changes: 1 error, 0 warning
    error   [new-required-request-property] at api-1.2.yaml
    in API POST /order
            added the new required request property 'quantity'