I have a new .NET6 Azure Functions application. I created a few HTTP functions with OpenAPI specifications.
My swagger page is working fine, except for the POST function.
I would like to show a minimal body request on this page as an example.
I've implemented IOpenApiExample as mentioned at https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/openapi-core.md#openapirequestbodyattribute
but the example is not used. It keeps showing the whole model without any sample values.
This is my relevant code:
[FunctionName("PostHistoryEvent")]
[OpenApiOperation(operationId: "PostHistoryEvent", tags: new[] { "Post HistoryEvent" })]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody("application/json", typeof(HistoryEvent), Required = true, Description = "Description of OpenApiRequestBody", Example = typeof(HistoryEventOpenApiExample))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.Created, contentType: "application/json", bodyType: typeof(HistoryEvent), Description = "The created History Event")]
public async Task<IActionResult> PostHistoryEvent(...){...}
public class HistoryEventOpenApiExample : OpenApiExample<HistoryEvent>
{
public override IOpenApiExample<HistoryEvent> Build(NamingStrategy namingStrategy = null)
{
Examples.Add(OpenApiExampleResolver.Resolve(
"first",
new HistoryEvent()
{
ObjectId = "foo",
More properties ...
},
namingStrategy));
return this;
}
}
I assume I need to do add something, but I'm not sure what.