In swagger, can I use the whole post request body as plain text parameter?

Viewed 190

In some documents it says it allows this:

parameters:
  - name: body
    'in': 'body'
    required: true
    schema:
      type: string

But in reality, the in argument can only be path, query, cookie or header.

I also could not skip the parameters, because it would generate the wrong rust code.

2 Answers

Yes! As described in the docs, here (under 'Primitive Body'): https://swagger.io/docs/specification/2-0/describing-request-body/

In your swagger.yml you can specify it like so:

    paths:
      /status:
        post:
          summary: Updates the status message.
          consumes:
            - text/plain      # <----------
          parameters:
            - in: body
              name: status
              required: true
              schema:
                type: string  # <----------
          responses:
            200:
              description: Success!

This is the exact code snipped from the docs, pasted here for your convenience. :)

No I don't think there is any way you can make the request body object part of your parameter object anymore, but you could skip your parameters with:

parameters: []

Related