Skip to content

DIFF command panics when definition property type changes from an array to a non-array type #2894

@zmay2030

Description

@zmay2030

Problem statement

When a definition property changes from array type to another non-array type, the swagger DIFF results in a panic.

Steps to reproduce

spec_1.json

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Fixture",
    "version": "1.0"
  },
  "paths": {
    "/a/": {
      "get": {
        "parameters": [
          {
            "name": "",
            "in": "body",
            "schema": { "$ref": "#/definitions/A1" }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "array",
              "items": { "$ref": "#/definitions/A1" }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "A1": {
      "type": "object",
      "properties": {
        "a": { "type": "array" }
      }
    }
  }
}

spec_2.json

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Fixture",
    "version": "1.0"
  },
  "paths": {
    "/a/": {
      "get": {
        "parameters": [
          {
            "name": "",
            "in": "body",
            "schema": { "$ref": "#/definitions/A1" }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "array",
              "items": { "$ref": "#/definitions/A1" }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "A1": {
      "type": "object",
      "properties": {
        "a": { "type": "object" }
      }
    }
  }
}

Then Run swagger diff spec_1.json spec_2.json.

It was result in a panic

goroutine 1 [running]:
github.com/go-swagger/go-swagger/cmd/swagger/commands/diff.getTypeFromSchemaProps(0x1400054e488)
        /projects/go-swagger/cmd/swagger/commands/diff/schema.go:50 +0x138
github.com/go-swagger/go-swagger/cmd/swagger/commands/diff.getSchemaType({0x10549a9e0?, 0x1400054e488?})
        /projects/go-swagger/cmd/swagger/commands/diff/schema.go:69 +0x108
github.com/go-swagger/go-swagger/cmd/swagger/commands/diff.fromSchemaProps(...)
        /projects/go-swagger/cmd/swagger/commands/diff/spec_analyser.go:489

Environment

swagger version: 2.0
go version: 1.18
OS: Mac Monterey

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