2017-10-06 107 views
1

我試圖定義使用招搖後端點,但不允許requestBody參數:招搖:requestBody不允許

/names/{roster}: 
    get: 
     #... 
    post: 
     x-swagger-router-controller: names 
     description: Adds or removes name(s) 
     operationId: manageNames 
     parameters: 
     - name: roster 
     in: path 
     description: the roster to use 
     type: string 
     required: true 
     requestBody: 
     content: 
      'application/json': 
      schema: 
       $ref: '#/definitions/ManageNamesRequest' 

當我運行npm start,我得到這個:

API Errors: 

    #/paths/~1names~1{roster}/post: Additional properties not allowed: requestBody 

1 error and 0 warnings 

我的規格有什麼問題?

+0

'requestBody'是OpenAPI的3.0語法。你的工具是否支持OpenAPI 3.0? – Helen

+0

我正在使用swagger版本2.0。我不確定? – ewok

回答

2

您可能正在混合使用OpenAPI/Swagger 2.0和OpenAPI 3.0語法。您的規範似乎是2.0,但requestBody關鍵字是3.0功能。在2.0中,請求體被定義爲身體參數:

paths: 
    /names/{roster}: 
    post: 
     produces: 
     - application/json 
     ... 
     parameters: 
     - ... 
     - in: body 
     name: body 
     required: true 
     schema: 
      $ref: '#/definitions/ManageNamesRequest' 

更多信息:Describing Request Body