1

我的 OpenAPI 规范文件有问题。我试图调用一个暴露的 url 来“获取”一个 id,但是每次我将服务转发到我的本地然后尝试通过 API 文档发送请求时,我的连接都被拒绝了。我将不胜感激任何帮助。我期望的 id 将采用 JSON 格式。下面是我的规格文件

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Id Generator
servers:
   url: www.someurl.com
paths:
  /posts:
    get:
      summary: Get Id
      operationId: id
      tags:
        - posts
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
              $ref: "#/definition/Post"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
              $ref: "#/definition/Error"

definition:
    Post:
    type: object 
    properties:
        id:
          type: string
    Error:
      properties:
        id:
          type: string
4

1 回答 1

1

截至 2017 年 6 月 21 日,OpenAPI 规范 3.0 尚未发布,Swagger UI 还不支持 OpenAPI 3.0,因此您的示例可能无法运行。密切关注Swagger UI 发布页面,了解何时支持 OpenAPI 3.0。

此外,您需要修复规范中的错误以使其成为有效的 OpenAPI 3.0 规范:

  • servers是一个数组,所以将其更改为:

    servers:
      - url: http://www.someurl.com
    
  • 必须引用响应状态代码:"200"'200'

  • 缩进$ref下面的模式:

                  schema:
                    $ref: "#/definition/Post"
                  ...
                  schema:
                    $ref: "#/definition/Error"
    
  • 更改definitioncomponents->schemas并修复 的缩进Post

    components:
      schemas:
        Post:
          type: object 
          properties:
            id:
              type: string
        Error:
          properties:
            id:
              type: string
    
于 2017-06-21T13:29:05.557 回答