Swashbuckle how to show an example dictionary instead of additionalProp?

Viewed 88

I have an API and I want swashbuckle to autogenerate all the swagger documentation for me.

I have an endpoint that returns a class with a dictionary property but the swagger generated example contains "additionalProp1, additionalProp2" etc instead of example values. Is there a way to instead use example values specified in the SimpleClass class?

The class with the example for swagger (that doesn't work).

public class SimpleClass
{
    /// <example>"{"age":31,"height":234}"</example>
    public Dictionary<string, int> DictionaryProperty { get; set; }

    /// <example>The cow jumped over the moon</example>
    public string someProperty { get; set; }
}

The controller

    [HttpGet]
    [Route("/testexample")]
    [ProducesResponseType(typeof(SimpleClass), StatusCodes.Status200OK)]
    public async Task<IActionResult> TestExample()
    {
        return Ok();
    }

The result in swagger: enter image description here

1 Answers

Take out the quotes inside the XML example value:

/// <example>{"age":31,"height":234}</example>
Related