Skip to content

SwaggerUI doesn't render example values for a non-enumerable types #2156

@StasPerekrestov

Description

@StasPerekrestov

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).

image

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

image

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions