如何定义以整数结尾的URL?

时间:2019-11-27 15:57:16

标签: swagger openapi

下面的OpenAPI定义将生成的URL为http://localhost:9200/GetCourse?id=1。如何更改定义以将URL生成为http://localhost:9200/GetCourse/1

  /GetCourse:
    get:
      summary: Get Courses
      description: >
        The GetCourse details.
      tags:
        - Content information
      parameters:
        - name: id
          in: query
          description: The ID of the HEI being queried
          required: true
          type: integer
      responses:
        '200':
          description: An array of courses
          schema:
            $ref: '#/definitions/Courses'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

1 个答案:

答案 0 :(得分:1)

  1. 将参数位置(in)从query更改为path
  2. 在路径名的末尾添加/{id}
paths:
  /GetCourse/{id}:   # <----
    get:
      ...
      parameters:
        - name: id
          in: path   # <----
          description: The ID of the HEI being queried
          required: true
          type: integer