【问题标题】:Swagger.json generating with incorrect case "type": "String"Swagger.json 生成不正确的大小写“类型”:“字符串”
【发布时间】:2020-09-13 03:00:26
【问题描述】:

在对this problem 进行故障排除时,我们发现 swagger.json 包含不正确的大小写 for

“类型”:“字符串”

在生成的代码中

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

我有以下 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)
                }
            );
    }
}

这可能是什么原因造成的?

【问题讨论】:

    标签: swashbuckle.aspnetcore


    【解决方案1】:

    原来是我用的

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

    在我的课堂里

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

    它应该有“字符串”作为小写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 2015-07-14
      • 2011-12-11
      • 2010-12-27
      • 1970-01-01
      相关资源
      最近更新 更多