Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zmay2030 opened this issue Feb 1, 2023 · 0 comments · Fixed by #2895
Closed

Comments

@zmay2030
Copy link
Contributor

zmay2030 commented Feb 1, 2023

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

zmay2030 pushed a commit to zmay2030/go-swagger that referenced this issue Feb 1, 2023
zmay2030 pushed a commit to zmay2030/go-swagger that referenced this issue Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant