SwashBuckle does not produce a swagger.json that is `swagger 2.0` compliant

Viewed 273

We are using SwashBuckle 5.0 and trying to produce a swagger doc 2.0. And apparently it does produce swagger.json which is not 100% compliant with swagger 2.0 specs. The problem is specifically around how it does enlists the enums:

name: prop-name
description: something
type: array
items:
    $ref: '#/definitions/mytype'

where it should had been :

name: prop-name
description: something
type: array
items:
  type: string
  enum:
    - Item1

For it to be 100% swagger 2.0 spec.So jus tto summarize, SwashBuckle has produced a swagger.json for us which is not 100% swagger 2.0 complaint. We are enforcing our configuration to use V2 by spefically saying SerializeAsV2 = true

We also considered upgrading to OAS 3.0 and decided against to for now since all of the clients have to change and it is a big effort. So we are back to trying to figure out how can have have SwashBuckle produce a swagger.json that is 100% swagger 2.0 complaint? I just want to see if there is not a configuration that we need to change before I file a bug against SwashBuckle team.

Any suggestions?

1 Answers

I started by quickly testing your pattern on http://editor.swagger.io and I did not get any error...

Here is my attempt to reproduce your code:
https://github.com/heldersepu/csharp-proj/blob/master/WebApi_NetCore/WebApi_NetCore/Controllers/ErrorController.cs#L19-L42

        [HttpPost]
        public List<MonthEnum> Enum(string id)
        {
            var l = new List<MonthEnum>();
            l.Add(MonthEnum.July);
            l.Add(MonthEnum.August);
            return l;
        }

That give us:
https://raw.githubusercontent.com/heldersepu/hs-scripts/master/swagger/swagger_enum.json

    "/api/Error": {
        "post": {
          "tags": [
            "Error"
          ],
          ...
          "responses": {
            "200": {
              "description": "Success",
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/MonthEnum"
                }
              }
            }
          }
        }
      },
      ...
    },
    "definitions": {
      ...
      "MonthEnum": {
        "format": "int32",
        "enum": [
          0,
          1,
          ...
        ],
        "type": "integer"
      }
    }

The Swagger UI says it's valid:
http://petstore.swagger.io/?url=https://raw.githubusercontent.com/heldersepu/hs-scripts/master/swagger/swagger_enum.json

The validator does not have any errors:
https://validator.swagger.io/validator/debug?url=https%3A%2F%2Fraw.githubusercontent.com%2Fheldersepu%2Fhs-scripts%2Fmaster%2Fswagger%2Fswagger_enum.json

Maybe there is something else wrong in your swagger schema

Related