Skip to content
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

Incorrect Detection of Breaking Change for Default Values #549

Closed
Krzysztof-Kolodziejczyk opened this issue May 28, 2024 · 0 comments · Fixed by #551
Closed

Incorrect Detection of Breaking Change for Default Values #549

Krzysztof-Kolodziejczyk opened this issue May 28, 2024 · 0 comments · Fixed by #551
Assignees
Labels
bug Something isn't working

Comments

@Krzysztof-Kolodziejczyk

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

  • oasdiff Version: 1.10.9
  • OpenAPI Specification Files: Version 1.1 and 1.2

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
  1. 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
  1. 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'
@Krzysztof-Kolodziejczyk Krzysztof-Kolodziejczyk added the bug Something isn't working label May 28, 2024
@reuvenharrison reuvenharrison self-assigned this May 28, 2024
@reuvenharrison reuvenharrison linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants