2016-02-29 23 views
0

我想寫與揚鞭的UI(招搖版本2.0)一個開放的API規範,我不知道如何表示與path參數開放API POST

POST /ping/{text}

一個 POST參數

我的規格如下,

# this is an example of the Uber API 
# as a demonstration of an API spec in YAML 
swagger: '2.0' 
info: 
    title: Mock API 
    description: Mock API 
    version: "1.0.0" 
# the domain of the service 
host: api.mock.com 
# array of all schemes that your API supports 
schemes: 
    - https 
# will be prefixed to all paths 
basePath: /v1 
produces: 
    - application/json 
paths: 
    /ping: 
    get: 
     summary: Ping 
     description: | 
     Respond to PING requests, similar to heart beat 
     parameters: 
     - name: path 
      in: path 
      description: String input for echo service 
      required: false 
      type: string 
     tags: 
     - ping 
     responses: 
     200: 
      description: The text passed in the request 
      schema: 
      type: string 
     default: 
      description: Empty response for request passed 
      schema: 
      type: string 

而招搖UI顯示錯誤如下 -

code: "ONE_OF_MISSING" 
message: "Not a valid parameter definition" 

但是如果我將其更改爲in: query錯誤消失。我究竟做錯了什麼?或者在開放式API規範中指定路徑參數的正確方法是什麼?

回答

1

有你需要對你的文件以符合Open API specification一些改變。

1-的name字段應該匹配路徑段(即text

如果是「路徑」時,名稱字段必須在對應於相關聯的路徑段從路徑字段路徑對象。見路徑模板進一步的信息。

required: true 2-應添加。

如果參數在「路徑」中,則此屬性是必需的,其值必須爲真。

3-如果你想記錄POST /ping/{text}get需要改變,以post。路徑段(即/{text)也應該添加到路徑中。

這裏是上面描述的變化後的最終揚鞭DOC:打開`required`到TRUE;仍然顯示相同的錯誤

# this is an example of the Uber API 
# as a demonstration of an API spec in YAML 
swagger: '2.0' 
info: 
    title: Mock API 
    description: Mock API 
    version: "1.0.0" 
# the domain of the service 
host: api.mock.com 
# array of all schemes that your API supports 
schemes: 
    - https 
# will be prefixed to all paths 
basePath: /v1 
produces: 
    - application/json 
paths: 
    /ping/{text}: 
    post: 
     summary: Ping 
     description: | 
     Respond to PING requests, similar to heart beat 
     parameters: 
     - name: text 
      in: path 
      description: String input for echo service 
      required: true 
      type: string 
     tags: 
     - ping 
     responses: 
     200: 
      description: The text passed in the request 
      schema: 
      type: string 
     default: 
      description: Empty response for request passed 
      schema: 
      type: string