-
Notifications
You must be signed in to change notification settings - Fork 199
How to display Enum values in generated OpenAPI Document as 'string' instead of 'numbers'? #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can do this with APIs, but would require |
|
Alright. I was able to find a reason after creating a completely new function app. By default my already existing code had Try using |
Made a quick example using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Example
{
// Define the enum type with the JsonConverter attribute.
// NOTE: Check that this uses Newtonsoft.Json instead of System.Text.Json.Serialization
[JsonConverter(typeof(StringEnumConverter))]
public enum BusinessFunction
{
Liner = 100000000,
Trucking = 100000001
}
public static class Function
{
// Use the OpenApiParameter attribute to specify the enum type and name
[FunctionName("Function")]
[OpenApiOperation(operationId: "run", tags: new[] { "example" })]
[OpenApiParameter(name: "businessFunction", In = ParameterLocation.Query, Required = true, Type = typeof(BusinessFunction))]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req) // Use the enum type as the function parameter
{
var dict = req.GetQueryParameterDictionary();
dict.TryGetValue("businessFunction", out var val );
// Do something with the ruleType parameter
return new OkObjectResult($"You selected {val}");
}
}
} |
Any updates on the issue?
|
I have defined a Transport enum as below, i want the Open API Specification to show the enum values as string instead of numeric.
Current behaviour

**Environment
The text was updated successfully, but these errors were encountered: