Kirsten
Kirsten

Reputation: 18076

Swagger.json generating with incorrect case "type": "String"

In troubleshooting this problem we found that swagger.json contained incorrect case for

"type": "String"

in the generated code

  "/api/FrameLookUp": {
      "post": {
        "tags": [
          "Frame"
        ],
        "operationId": "FrameLookup",
        "consumes": [
          "application/json-patch+json",
          "application/json",
          "text/json",
          "application/*+json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "in": "header",
            "name": "Authorization",
            "description": "access token",
            "required": true,
            "type": "String"
          },
          {
            "in": "body",
            "name": "body",
            "schema": {
              "$ref": "#/definitions/FrameRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "$ref": "#/definitions/FrameResponse"
            }
          }
        }
      }
    }
  }

I have the following ISchemaFilter

public class SwaggerEnumFilter : ISchemaFilter
{
    public void Apply(OpenApiSchema model, SchemaFilterContext context)
    {
         
        if (model == null)
            throw new ArgumentNullException("model");
        if (context == null)
            throw new ArgumentNullException("context");
        if (context.Type.IsEnum)
            model.Extensions.Add(
                "x-ms-enum",
                new OpenApiObject
                {
                    ["name"] = new OpenApiString(context.Type.Name),
                    ["modelAsString"] = new OpenApiBoolean(false)
                }
            );
    }
}

What could be causing this?

Upvotes: 1

Views: 456

Answers (1)

Kirsten
Kirsten

Reputation: 18076

It turned out to be that I was using

services.AddSwaggerGen(c =>
        {
            c.OperationFilter<AuthorizationHeaderParameterOperationFilter>();

and inside the class I had

Schema = new OpenApiSchema() { Type = "String" },

it should have had "string" as lower case.

Upvotes: 1

Related Questions