小编Dav*_*ing的帖子

如何在 ASP.NET Core 中正确设置 Swagger 示例?

我的目标:

为了仅在使用 SwaggerRequestExample 注释的端点上正确设置 OpenApi JSON 文档中的请求示例,而不是端点响应或缺少此属性的其他端点。

预期结果:

"post": {
    "tags": [
      "Address"
    ],
    "requestBody": {
      "content": {
        },
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Address"
          },
          "example": {"id":"995ace6e-33d5-4efd-860e-b653fef60dad","binaryAddress":246,"distance":123}
        }
        }
      }
    },
    "responses": {
      "200": {
        "description": "Success",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Address"
            }
          }
          }
        }
      }
Run Code Online (Sandbox Code Playgroud)

实际结果:

"post": {
    "tags": [
      "Address"
    ],
    "requestBody": {
      "content": {
        },
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Address"
          },
          "example": {"id":"995ace6e-33d5-4efd-860e-b653fef60dad","binaryAddress":246,"distance":123}
        }
        }
      }
    },
    "responses": {
      "200": { …
Run Code Online (Sandbox Code Playgroud)

c# swagger .net-core asp.net-core openapi

10
推荐指数
1
解决办法
5779
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

c# ×1

openapi ×1

swagger ×1