Skip to content

diff result has no URL, when there is an object type array field in the schema #2964

@EarthSoar

Description

@EarthSoar

Problem statement

When the type of a certain attribute in the request or response is an array, and the item of the array is an object type, when changing the field of the array item, the result of the swagger diff is that there is no URL.

Swagger specification

old-swagger.json

{
  "swagger": "2.0",
  "info": {
    "title": "Uber API",
    "description": "Move your app forward with the Uber API",
    "version": "1.0.0"
  },
  "host": "api.uber.com",
  "schemes": [
    "https"
  ],
  "basePath": "/v1",
  "produces": [
    "application/json"
  ],
  "paths": {
    "/history": {
      "get": {
        "summary": "User Activity",
        "parameters": [
          {
            "name": "offset",
            "in": "query",
            "type": "integer",
            "format": "int32",
            "description": "Offset the list of returned results by this amount. Default is zero."
          },
          {
            "name": "limit",
            "in": "query",
            "type": "integer",
            "format": "int32",
            "description": "Number of items to retrieve. Default is 5, maximum is 100."
          }
        ],
        "tags": [
          "User"
        ],
        "responses": {
          "200": {
            "description": "History information for the given user",
            "schema": {
              "$ref": "#/definitions/Activities"
            }
          },
          "default": {
            "description": "Unexpected error",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Activity": {
      "properties": {
        "uuid": {
          "type": "string",
          "description": "Unique identifier for the activity"
        }
      }
    },
    "Activities": {
      "properties": {
        "offset": {
          "type": "integer",
          "format": "int32",
          "description": "Position in pagination."
        },
        "limit": {
          "type": "integer",
          "format": "int32",
          "description": "Number of items to retrieve (100 max)."
        },
        "count": {
          "type": "integer",
          "format": "int32",
          "description": "Total number of items available."
        },
        "history": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "Error": {
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "fields": {
          "type": "string"
        }
      }
    }
  }
}

new-swagger.json

{
  "swagger": "2.0",
  "info": {
    "title": "Uber API",
    "description": "Move your app forward with the Uber API",
    "version": "1.0.0"
  },
  "host": "api.uber.com",
  "schemes": [
    "https"
  ],
  "basePath": "/v1",
  "produces": [
    "application/json"
  ],
  "paths": {
    "/history": {
      "get": {
        "summary": "User Activity",
        "parameters": [],
        "tags": [
          "User"
        ],
        "responses": {
          "200": {
            "description": "History information for the given user",
            "schema": {
              "$ref": "#/definitions/Activities"
            }
          },
          "default": {
            "description": "Unexpected error",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Activity": {
      "properties": {
        "uuid": {
          "type": "string",
          "description": "Unique identifier for the activity"
        },
        "uuid2": {
          "type": "string",
          "description": "Unique identifier for the activity"
        }
      }
    },
    "Activities": {
      "properties": {
        "history": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Activity"
          }
        }
      }
    },
    "Error": {
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "fields": {
          "type": "string"
        }
      }
    }
  }
}

The difference between new-swagger.json and old-swagger.json:

{
  ...
  "definitions": {
    "Activity": {
      "properties": {
        "uuid": {
          "type": "string",
          "description": "Unique identifier for the activity"
        },
  ++      "uuid2": {
  ++       "type": "string",
  ++       "description": "Unique identifier for the activity"
        }
      }
    },
   
}

Steps to reproduce

run swagger diff command, result is saved in diff.json file

swagger diff -f json -d diff.json old-swagger.json new-swagger.json

cat diff.json
[
  {
    "location": {
      "url": "",
      "node": {
        "name": "Spec Definitions",
        "child": {
          "name": "Activity",
          "child": {
            "name": "uuid2",
            "type": "string"
          }
        }
      }
    },
    "code": "AddedProperty",
    "compatibility": "Breaking"
  }
]

There is no URL in location, and the name field is still Spec Definitions

Environment

swagger version: v0.30.5
go version: 1.20.1
OS: mac os 13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions