0

我正在使用 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=bar在这里,我支持对和的请求http://example.com/WS/Login?UserID=foo&Token=dubdu22r8dwjgd767dg

swagger 编辑器没有显示上述 yaml 的任何错误,但它只为第二个路径(具有 UserId 和 Token 查询参数的路径)生成文档,而不是两者。有人可以指出我哪里出错了吗?谢谢。

编辑:

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

我还想到,我可以指定一个/Login:带有必需参数和UserID可选参数的路径。但是我如何指定必须提供其中一个和必须提供?PasswordTokenUserIDPassword

4

1 回答 1

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
于 2015-09-18T18:11:56.267 回答