cnak2
cnak2

Reputation: 1841

Swagger says"not a valid parameter defenition"

I'm fairly new to swagger and would appreciate some direction on good resources for learning.

I have a test project that I'm putting together and I am running into some issues.

I'm getting an error saying that the "parameters" in my "delete" block is not valid. It looks ok to me from what I've seen in the examples. But apparently I'm missing something. Any ideas?

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

Upvotes: 0

Views: 98

Answers (1)

Arnaud Lauret
Arnaud Lauret

Reputation: 5331

You just need to describe the id parameter in the delete /guestbook/{id} operation just like you did in 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

You can also define this parameter once for all operations of path /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

If you need to learn how to write OpenAPI (fka. Swagger) specification files, you can read my Writing OpenAPI/Swagger Specification Tutorial

Upvotes: 1

Related Questions