NSwag: SwaggerUI doesn't render example values for a non-enumerable types
Hi,
It seems to me, there is an issue related to example values generation logic for asp.net controllers when a controller returns a single value (in a case when OAS3 is used).

The screenshot relates to this code
However, if you just for the sake of experiment change the return type from
[ProducesResponseType(typeof(Pet), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(SerializableError), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<Pet>> FindById(int petId)
{
to
ProducesResponseType(typeof(IEnumerable<Pet>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(SerializableError), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<IEnumerable<Pet>>> FindById(int petId)
{
it generates the expected example value

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (18 by maintainers)
But could you solve your problem?
Yes, this is because response reference types are nullable by default, see https://github.com/RicoSuter/NSwag/issues/2071
Try to set
DefaultResponseReferenceTypeNullHandlingtoReferenceTypeNullHandling.NotNull(maybe this should be the default - but it is not really correct and changing the default might break users)