Gerando Swagger.json com “tipo” de caixa incorreta: “String”

Sep 12 2020

Ao solucionar este problema , descobrimos que swagger.json continha uma caixa incorreta para

"tipo": "String"

no código gerado

  "/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"
            }
          }
        }
      }
    }
  }

Eu tenho o seguinte 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)
                }
            );
    }
}

O que poderia estar causando isso?

Respostas

1 KirstenGreed Sep 13 2020 at 03:17

Acontece que eu estava usando

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

e dentro da aula que eu tive

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

deveria ter "string" em minúsculas.