Skip to content

Adding an optional field to request body shouldn't be a breaking change #2962

@schafle

Description

@schafle

Problem Statement

Adding an optional field to request body shouldn't be a breaking change but it seems the breaking tool identify it as a breaking change

Steps to reproduce

Before

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Fixture",
    "version": "1.0"
  },
  "paths": {
    "/a/{id}": {
      "post": {
        "parameters": [
          {
            "name": "",
            "in": "body",
            "schema": { "$ref": "#/definitions/A2" }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "schema": { "$ref": "#/definitions/A3" }
          }
        }
      }
    }
  },
  "definitions": {
    "A2": {
      "type": "object",
      "required": [ "name", "description" ],
      "properties": {
        "name": { "type": "string" },
        "description": { "type": "string" }
      }
    },
    "A3": {
      "type": "object",
      "properties": {
        "id": { "type": "integer" },
        "name": { "type": "string" },
        "otherDeletedName":{"type":"string","deprecated":true},
        "description": { "type": "string" },
        "letters": {
          "type": "array",
          "items": { "type": "string" }
        },
        "attributes": {
          "type": "object",
          "additionalProperties": { "type": "string" }
        }
      }
    }
  }
}

After

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Fixture",
    "version": "1.0"
  },
  "paths": {
    "/a/{id}": {
      "post": {
        "parameters": [
          {
            "name": "",
            "in": "body",
            "schema": { "$ref": "#/definitions/A2" }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "schema": { "$ref": "#/definitions/A3" }
          }
        }
      }
    }
  },
  "definitions": {
    "A2": {
      "type": "object",
      "required": [ "name", "description" ],
      "properties": {
        "name": { "type": "string" },
        "description": { "type": "string" },
        "field3": { "type": "string" }
      }
    },
    "A3": {
      "type": "object",
      "properties": {
        "id": { "type": "integer" },
        "name": { "type": "string" },
        "otherDeletedName":{"type":"string","deprecated":true},
        "description": { "type": "string" },
        "letters": {
          "type": "array",
          "items": { "type": "string" }
        },
        "attributes": {
          "type": "object",
          "additionalProperties": { "type": "string" }
        }
      }
    }
  }
}

The diff tool should say there's a non-breaking change but it says there's a breaking change.

swagger diff old.json new.json
2023/08/16 22:56:08 Run Config:
2023/08/16 22:56:08 Spec1: old.json
2023/08/16 22:56:08 Spec2: new.json
2023/08/16 22:56:08 ReportOnlyBreakingChanges (-c) :false
2023/08/16 22:56:08 OutputFormat (-f) :txt
2023/08/16 22:56:08 IgnoreFile (-i) :none specified
2023/08/16 22:56:08 Diff Report Destination (-d) :stdout
BREAKING CHANGES:
=================
/a/{id}:post - Request - Body.field3<string> - Added property
compatibility test FAILED: 1 breaking changes detected
compatibility test FAILED: 1 breaking changes detected

Environment

go version: 1.20.4
OS: macOS 13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdiffRelates to the swagger diff commandpending PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions