openapi-diff icon indicating copy to clipboard operation
openapi-diff copied to clipboard

ChangedSchema in a readOnly property for requestBody is not filtered out from the result.

Open terrykang90 opened this issue 3 years ago • 0 comments

Old API
{
  "openapi":"3.0.0",
  "info":{
    "title":"API",
    "version":"0.1.0"
  },
  "paths":{
    "/resource":{
      "post":{
        "responses":{
          "200":{
            "description":"Created resource",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/CreateResourceResponse"
                }
              }
            }
          }
        },
        "summary":"Create resource",
        "requestBody":{
          "content":{
            "application/json":{
              "schema":{
                "$ref":"#/components/schemas/CreateResourceRequest"
              }
            }
          },
          "description":"Definition of the resource"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateResourceResponse": {
        "type": "object",
        "properties": {
          "resources": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "CreateResourceRequest": {
        "type": "object",
        "properties": {
          "foo": {
            "$ref": "#/components/schemas/Foo"
          }
        }
      },
      "Foo": {
        "type": "object",
        "properties": {
          "bar": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Bar"
            },
            "readOnly": true
          }
        }
      },
      "Bar": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    }
  }
}
New API
{
  "openapi":"3.0.0",
  "info":{
    "title":"API",
    "version":"0.1.0"
  },
  "paths":{
    "/resource":{
      "post":{
        "responses":{
          "200":{
            "description":"Created resource",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/CreateResourceResponse"
                }
              }
            }
          }
        },
        "summary":"Create resource",
        "requestBody":{
          "content":{
            "application/json":{
              "schema":{
                "$ref":"#/components/schemas/CreateResourceRequest"
              }
            }
          },
          "description":"Definition of the resource"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateResourceResponse": {
        "type": "object",
        "properties": {
          "resources": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "CreateResourceRequest": {
        "type": "object",
        "properties": {
          "foo": {
            "$ref": "#/components/schemas/Foo"
          }
        }
      },
      "Foo": {
        "type": "object",
        "properties": {
          "bar": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Bar"
            },
            "readOnly": true
          }
        }
      },
      "Bar": {
        "type": "object",
        "properties": {
          "name": {
            "type": "integer"
          }
        }
      }
    }
  }
}

In this example, the property bar in Foo schema is a readOnly property and Foo is referenced by request body of the endpoint. When Bar schema is changed, it's filtered out from the request body but the change exists in the list of ChangedSchema in ChangedOpenApi, which results incompatible changes but shows nothing.

==========================================================================
==                            API CHANGE LOG                            ==
==========================================================================
                                   API                                    
--------------------------------------------------------------------------
--                                Result                                --
--------------------------------------------------------------------------
                 API changes broke backward compatibility                 
--------------------------------------------------------------------------

terrykang90 avatar Mar 24 '22 00:03 terrykang90