-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community
Description
We are using mongodb which has an ObjectId type (struct). We use a JsonConverter to serialize this as a string, This converter is registered using builder.Services.AddJsonOptions. It works perfectly in our actual API.
However when the swagger is generated the examples have it serialised as an object:
"id": {
"timestamp": 0,
"creation_time": "2022-09-13T22:36:23.872Z"
}
Things we have tried which didn't work:
- using an example tag in the xml comments in the model (this works for other properties but not this one)
/// <summary>
/// </summary>
/// <example>123456456987</example>
public ObjectId Id { get; set; }
- using a ISchemaFilter to change the type and set the example (code gets hit but has no effect on example)
public class SwaggerDiversionFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
foreach(var property in schema.Properties)
{
if(context.Type == typeof(Diversion))
{
if(property.Key == "id")
{
property.Value.Example = new OpenApiString(new ObjectId().ToString());
property.Value.Type = "string";
}
}
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community