typescript-rest-swagger icon indicating copy to clipboard operation
typescript-rest-swagger copied to clipboard

How can I describe request body?

Open Emilian5 opened this issue 6 years ago • 2 comments

Hello.

How can I achieve the following:

    requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'

(https://swagger.io/docs/specification/describing-request-body/)

I've seen @BodyOptions but not sure if it's the right way.

Any suggestions? Thank you.

Emilian5 avatar Aug 04 '18 15:08 Emilian5

Any updated about this question?

marcussoliva avatar Jun 17 '20 14:06 marcussoliva

Just pass it to your parameters of your function

type Cat = {
   breed: string;
   age: number;
}

 @Example<object>({
    message: "ok",
  })
  @POST
  @Tags("Cat API")
  @Path("/add")
  @Response<{ message: string }>(200, "Success adding cat")
  @Consumes("application/json")
  @Accept("application/json")
  public mainFilters(body: Cat): object {
    return {
      message: "ok",
    };
  }

ovidubya avatar Sep 17 '20 17:09 ovidubya