2016-07-25 6 views
0

Я довольно новичок в чванстве и оценил бы какое-то направление в отношении хороших ресурсов для обучения.Swagger говорит, что «недействительное дефинитивное значение параметра»

У меня есть тестовый проект, который я собираю, и у меня возникают проблемы.

Я получаю сообщение об ошибке, что «параметры» в моем блоке «delete» недействительны. Это выглядит хорошо для меня из того, что я видел в примерах. Но, видимо, я что-то упускаю. Есть идеи?

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

Вам просто нужно описать параметр id в delete /guestbook/{id} operation так же, как вы это делали в get /guestbook/{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