tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Providing an example value for the request body doesn't seem possible...?

Open gkpo opened this issue 6 months ago • 2 comments

Sorting

  • I'm submitting a ...

    • [ ] bug report
    • [x] feature request
    • [ ] support request
  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

I expected to be able to provide example values for the input of a POST endpoint using the @Example decorator in TSOA. Specifically, I want to define an example for a body parameter, and have it appear in the generated Swagger/OpenAPI documentation.

What I tried

@Post()
@Security("api_key_and_user_id")
@Example<Journey>(JourneyResponseExample)
public async createJourney(
  @Request() request: express.Request,
  @Body() @Example<CreateJourneyRequest>({ // <-------- This is the bit i'd like to see reflected in the generated doc
    city: "Paris",
    categoryNames: ["Food"],
    from: 8,
    to: 23,
    price: [0, 1, 2, 3],
    lat: 48.856614,
    lng: 2.3522219,
    radius: 2
  }) body: CreateJourneyRequest
): Promise<Journey> {
  // ... rest of the method implementation
}

Current Behavior

The documentation is not including my example. Value. It does provide random values inferred from the CreateJourneyRequest type though:

// This is what I actually see generated in Swagger:
{
  "city": "string",
  "categoryNames": [
    "string"
  ],
  "from": 0,
  "to": 0,
  "price": [
    0
  ],
  "lat": 0,
  "lng": 0,
  "radius": 0
}

gkpo avatar Aug 09 '24 09:08 gkpo