Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger: requestBody not allowed

I'm trying to define a post endpoint using swagger, but it isn't allowing the requestBody parameter:

  /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'

when I run npm start, I get this:

API Errors:

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

1 error and 0 warnings

What's wrong with my spec?

like image 341
ewok Avatar asked Oct 06 '17 17:10

ewok


People also ask

What is Requestbody in swagger?

In Swagger terms, the request body is called a body parameter. There can be only one body parameter, although the operation may have other parameters (path, query, header).


1 Answers

You are probably mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be 2.0, but the requestBody keyword is a 3.0 feature. In 2.0, the request body is defined as a body parameter:

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

More info: Describing Request Body

like image 78
Helen Avatar answered Sep 29 '22 20:09

Helen