Swagger说“不是一个有效的参数防御”

时间:2016-07-25 16:29:09

标签: swagger swagger-2.0 swagger-editor

我很擅长招摇,并希望获得一些良好的学习资源方向。

我有一个我正在组合的测试项目,我遇到了一些问题。

我收到一条错误消息,说我的“删除”块中的“参数”无效。从我在示例中看到的内容看起来对我来说没问题。但显然我错过了一些东西。有什么想法吗?

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: my@email.address
  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 个答案:

答案 0 :(得分: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.Swagger)规范文件,可以阅读我的Writing OpenAPI/Swagger Specification Tutorial

相关问题