仅在查询参数名称中不同的路径

时间:2015-09-18 08:59:22

标签: rest yaml swagger swagger-editor

我正在使用swagger编辑器来记录现有的API,该API允许路径支持两个不同的请求,这些请求仅在其查询参数名称中有所不同。例如:

swagger: '2.0'
info:
  title: example
  version: 1.0.0
host: example.com
schemes:
  - http
basePath: /WS
paths:
  /Login:
    post:
      summary: Login
      description: |
        Log in
      parameters:
        - name: UserID
          in: query
          description: User ID
          required: true
          type: string
        - name: Password
          in: query
          description: User password
          required: true
          type: string
      responses:
        '200':
          description: Success
  /Login:
    post:
      summary: Login
      description: |
        Log in
      parameters:
        - name: UserID
          in: query
          description: User ID
          required: true
          type: string
        - name: Token
          in: query
          description: Authentication token
          required: true
          type: string
      responses:
        '200':
          description: Success

我支持http://example.com/WS/Login?UserID=foo&Passoword=barhttp://example.com/WS/Login?UserID=foo&Token=dubdu22r8dwjgd767dg的请求。

swagger编辑器没有显示上述yaml的任何错误,但它只生成第二个路径(具有UserId和Token queryparams的路径)的文档,而不是两者。谁能指出我哪里出错了?感谢。

修改

如果我将第二个/Login:路径更改为(例如)/Login1:,那么我会在文档中看到这两个路径。虽然不是解决方案。

我也可以指定一个/Login:路径,其中包含必需的UserID参数以及可选的PasswordToken参数。但是,如何指定必须提供 UserIDPassword

1 个答案:

答案 0 :(得分:0)

您可以改用路径参数,尝试使用:

swagger: '2.0'
info:
  title: example
  version: 1.0.0
host: example.com
schemes:
  - http
basePath: /WS
paths:
  /Login?UserID={id}&Password={password}:
    post:
      summary: Login
      description: Log in
      parameters:
        - name: id
          in: path
          description: User ID
          required: true
          type: string
        - name: password
          in: path
          description: User password
          required: true
          type: string
      responses:
        '200':
          description: Success
  /Login?UserID={id}&Token={token}:
    post:
      summary: Login
      description: Log in
      parameters:
        - name: id
          in: path
          description: User ID
          required: true
          type: string
        - name: token
          in: path
          description: Authentication token
          required: true
          type: string
      responses:
        '200':
          description: Success