Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

node.js - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...