Swagger/OpenAPI 3.0 问题及响应示例

标签 swagger swagger-ui swagger-editor openapi

这是我在 Swagger 编辑器在线查看的 OpenAPI 3.0 定义的简化版本。我试图获得错误代码 401 和 403 的两个响应,它们共享相同的架构,显示不同的示例 - 这似乎不起作用,我仍然看到引用的类型作为示例。

你能帮我找出这些定义有什么问题吗?

openapi: 3.0.0
info:
  version: '1.0'
  title: A service
paths:
  /doSomething:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: string
              example: A string
      responses:
        401:
          $ref: '#/components/responses/Unauthorized'
        403:
          $ref: '#/components/responses/Denied'
components:
  responses:
    Unauthorized:
      description: The endpoint cannot be reached because the request is not authorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: unauthorized
    Denied:
      description: The request's authorizations don't match the required ones needed to access the resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: permissions denied
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string

最佳答案

您的定义是正确的,响应示例显示在 Swagger Editor 3.6.5+ 和 Swagger UI 3.17.4+ 中。此外,Swagger UI 3.23.0+ 和 Editor 3.6.31+ 支持多个示例

关于Swagger/OpenAPI 3.0 问题及响应示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48551855/

相关文章:

python-3.x - 在 flasgger 中包含外部 yml 文件

javascript - 在 OpenAPI (Swagger) 中使用 HMAC-SHA256 身份验证测试 API 路由

node.js - 如何使用express从不同中间件的响应对象中获取数据

node.js - Swagger - 更改项目目录

swagger - 如何在 Swagger 2.0 中通过 body 发送默认值

rest - 在 Azure API 管理中管理多个 REST API

java - 从 json 反序列化到包含枚举的对象的问题

c# - 从 IDocumentFilter 中的方法和 Controller 获取所有 CustomAttributes,swashbuckle asp net core,swagger

swagger - Swagger查询参数中添加textarea

swagger - swagger-editor 将 json 或 yaml 保存到远程后端的选项是什么?