2016-07-25 43 views
0

我是相當新的招搖,並會讚賞一些方向上良好的學習資源。Swagger說:「不是一個有效的參數defenition」

我有一個測試項目,我放在一起,我遇到了一些問題。

我收到一個錯誤消息,說我的「刪除」塊中的「參數」無效。從我在例子中看到的內容來看,它看起來不錯。但顯然我錯過了一些東西。有任何想法嗎?

swagger: "2.0" 

info: 
    version: "2" 
    title: My Title 
    description: Provides services for vacation rentals site 
    termsOfService: Private 
    contact: 
    name: My Name 
    url: www.myurl.com 
    email: [email protected] 
    license: 
    name: MIT 
    url: http://opensource.org/licenses/MIT 
schemes: 
    - http 
host: myurl.com 
basePath: /api 

paths: 
    /guestbook: 
    get: 
     summary: Gets some persons 
     description: Returns a list containing all persons. 
     responses: 
     200: 
      description: A list of posts 
      schema: 
      type: array 
      items: 
       required: 
       - firstName 
       properties: 
       firstName: 
        type: string 
       lastName: 
        type: string 
       email: 
        type: string 
       comment: 
        type: string 
    post: 
     summary: Adds a comment to the guestbook 
     description: Adds a comment to the guestbook 
     parameters: 
     - name: firstname 
      in: formData 
      required: true 
      type: string 
     - name: lastname 
      in: formData 
      required: true 
      type: string 
     - name: email 
      in: formData 
      required: true 
      type: string 
     - name: comment 
      in: formData 
      required: true 
      type: string 

     responses: 
     201: 
      description: Shows a successful post 
     '405': 
      description: Invalid input 
    /guestbook/{id}: 
    get: 
     summary: Gets a single post 
     description: Returns a single post 
     operationId: getPost 
     parameters: 
     - name: id 
      in: path 
      description: ID of pet to fetch 
      required: true 
      type: integer 
      format: int64 
     responses: 
     200: 
      description: A list of posts 
      schema: 
      type: array 
      items: 
       required: 
       - firstName 
       properties: 
       id: 
        type: number 
       firstName: 
        type: string 
       lastName: 
        type: string 
       email: 
        type: string 
       comment: 
        type: string 
    delete: 
     summary: Removes a post 
     description: Removes a post 
     operationId: deletePost 
     parameters: 
     - name: id 
      in: path 
     responses: 
     200: 
      description: Post has been removed 

回答

1

你只需要描述在delete /guestbook/{id} operation就像你在get /guestbook/{id}做了id參數。

delete: 
    summary: Removes a post 
    description: Removes a post 
    operationId: deletePost 
    parameters: 
    - name: id 
     in: path 
     description: ID of pet to fetch 
     required: true 
     type: integer 
     format: int64 
    responses: 
    200: 
     description: Post has been removed 

您也可以爲路徑/guestbook/{id}的所有操作,一旦定義了這個參數:

/guestbook/{id}: 
    parameters: 
    - name: id 
     in: path 
     description: ID of pet to fetch 
     required: true 
     type: integer 
     format: int64 
    get: 
    summary: Gets a single post 
    description: Returns a single post 
    operationId: getPost 
    responses: 
     200: 
     description: A list of posts 
     schema: 
      type: array 
      items: 
      required: 
       - firstName 
      properties: 
       id: 
       type: number 
       firstName: 
       type: string 
       lastName: 
       type: string 
       email: 
       type: string 
       comment: 
       type: string 
    delete: 
    summary: Removes a post 
    description: Removes a post 
    operationId: deletePost 
    responses: 
     200: 
     description: Post has been removed 

如果你需要學習如何編寫的OpenAPI(FKA揚鞭)規範的文件,你可以閱讀我的Writing OpenAPI/Swagger Specification Tutorial

相關問題