C#C
C#4y ago
malkav

❔ Swagger Open API not showing Request examples in the UI

I've written an Azure Function with Open API in C#, but when I open up the Swagger/UI to test my Azure Function, the "Request Body" example only shows types instead of example values..

Here's the function:
public static class MyFunction
{
  [FunctionName("MyFunction")]
  [OpenApiOperation(operationId: "Run", tags: new[]{"Run"})]
  [OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Header)]
  [OpenApiRequestBody(
    contentType: "application/json; charset=utf-8",
    bodyType: typeof(MyFunctionRequest),
    Description = "Sample Description",
    Required = true,
    Example = typeof(MyFunctionRequestExample) )]
  [OpenApiResponseWithBody(
    statusCode: HttpStatusCode.OK,
    bodyType: typeof(MyFunctionResponse),
    Description = "The Ok Response",
    Example = typeof(MyFunctionResponseExample) )]
  public static async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null] HttpRequest req, ILogger log)
  {
    // Function logic
  }
}
Was this page helpful?