【问题标题】:How to implement an empty path in YAML file如何在 YAML 文件中实现空路径
【发布时间】:2021-01-21 12:44:28
【问题描述】:

我正在尝试实现以下调用:

POST https://host/sessions

删除 https://host/sessions/{session_id}

POST 调用是建立会话,DELETE 调用是注销已建立的会话。

那么,在 YAML 文件中,如何有一个空的基本路径?它目前是 YAML 文件中的斜线,因为它是必需的文件,但斜线是多余的。任何想法?谢谢。

swagger: '2.0'
info:
  version: '0.0.1'
  title: authenticate
  #description: To be provided
  #  #termsOfService:To be provided
  contact:
   name: test
basePath:  /sessions 
paths:
  /:
    post:
      summary: eatablish a session
      description: sessions is a collection.This POST creates a new session in the sessions collection and the name of the session returned by this command is the session token.
      consumes:
        - "application/json"
      parameters:
        - in: header
          name: user_name
          type: string
          required: true
        - in: header
          name: password
          type: string
          required: true          
      responses:
        200:
          description: establish a session successfully
        400:
          $ref: "#/responses/BadRequest"
        500:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'
            
  /{session_id}:
    delete:
      summary: log out
      description: use sessionid to log out an established session.
      produces:
        - application/json
      parameters:
        - in: path
          name: session_id
          type: string
          required: true
      responses:
        200:
          description: log out a session successfully
        400:
          $ref: "#/responses/BadRequest"
        500:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'

【问题讨论】:

    标签: rest yaml swagger


    【解决方案1】:

    招摇defines

    到单个端点的相对路径。字段名称必须以正斜杠 (/) 开头。

    因此,斜线是必需的,不能有空路径。

    【讨论】:

    • 谢谢,所以这意味着 URI 必须是 POST host/sessions/,而不是 POST host/sessions,对吧?
    • 你总是可以使用basePath: /,然后使用/sessions/sessions/{session_id} 作为路径。这个想法是所有路径都必须在基本路径内,而基本路径本身不是(而/ 是)。我不确定查询是否可以在没有斜杠的情况下正常工作;但是您始终可以配置您的网络服务器来转发它。
    猜你喜欢
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2020-06-01
    • 2020-05-13
    • 2023-03-05
    • 2022-08-19
    • 2013-07-12
    • 2017-03-16
    相关资源
    最近更新 更多