Swashbuckle: generate sensible schema and example for dictionary with Guid keys?

35 Views Asked by At

I'm trying to make a REST interface.

Swashbuckle handily generates a sensible JSON and schema for FancyEntity in another GET request, but the problem arises when I define a GET request returns a Dictionary<Guid, FancyEntity>. I get the following example:

{
  "additionalProp1": {
    "world": "string",
    "sendAt": "2024-02-06T12:46:06.301Z"
  },
  "additionalProp2": {
    "world": "string",
    "sendAt": "2024-02-06T12:46:06.301Z"
  },
  "additionalProp3": {
    "world": "string",
    "sendAt": "2024-02-06T12:46:06.301Z"
  }
}

and the schema specifies < * >: as the keys.

Is there a way to provide some example Guids instead of additionalPropN and get the schema to say string($uuid)?

ETA: code is basically this:

public class HelloWorldController(IUniversalEventService<HelloWorldEvent> service)
    : BaseEventController<HelloWorldEvent>(service)
{
    /* ... */
    [HttpGet(GetAllSchedulesRoute)]
    [ProducesResponseType<Dictionary<Guid, HelloWorldEvent>>((int)HttpStatusCode.OK)]
    public override Task<IActionResult> GetAllSchedules(CancellationToken cancel = default) =>
        base.GetAllSchedules(cancel);
    /* ... */
}
0

There are 0 best solutions below