如何在YAML文件中实现空路径

问题描述

我正在尝试实现以下调用

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'

解决方法

挥舞defines

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

因此,斜杠是必需的,并且您不能有空路径。