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
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
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
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
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'
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
OpenAPI Specification File 1.1 (
api-1.1.yaml
):OpenAPI Specification File 1.2 (
api-1.2.yaml
):Run
oasdiff
on these files: Use the following command to compare the two versions of the API specifications:Output