If (propertyEnums != null & propertyEnums.Count > 0) Public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)įoreach (var property in (x => x.Value?.Enum?.Count > 0)) class SwaggerAddEnumDescriptions : IDocumentFilter It could be more efficient by not searching for the enum type twice in some cases. All these problems are addressed in the code below. The previous answer also works only if a property is named exactly like it's type. I have modified Hosam Rehani's answer to work with nullable enums and with collection of enums also. Return string.Join(", ", enumDescriptions.ToArray()) List possibleParameterisedOperations = new List ", enumInt, Enum.GetName(enumType, enumInt))) add enum descriptions to input parametersįoreach (PathItem pathItem in )ĭescribeEnumParameters(pathItem.parameters) scription += DescribeEnum(propertyEnums) IList propertyEnums = (propertyEnums != null & propertyEnums.Count > 0) Schema property = propertyDictionaryItem.Value Schema schema = schemaDictionaryItem.Value įoreach (KeyValuePair propertyDictionaryItem in schema.properties) add enum descriptions to result modelsįoreach (KeyValuePair schemaDictionaryItem in finitions) Public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) Public class SwaggerAddEnumDescriptions : IDocumentFilter SwaggerAddEnumDescriptions.cs: using System The best issue I've found to follow is which looks like a "maybe soon" but then Swagger would have to be updated, and in my case Swashbuckle as well.įor now my workaround has been to implement a document filter that looks for enums and populates the relevant description with the contents of the enum. It's not possible to specify names and numbers for enums. So from my research this ultimately seems to be a limit of the OpenAPI specification which Swagger uses. The swagger-ui matters less, what I really want is code generation with a "real" enum on the other side (android apps using retrofit in this case). I'm looking for swagger to generate enums along with the int -> string mapping. Public IHttpActionResult GetByPriority (Priority priority) In the documentation for this request I want to see the string values of the enum before submitting: Low, Medium, High. Validation not passing when using DescribeEnumsAsStrings Public IHttpActionResult SendLetter(Letter letter) Public class LettersController : ApiController I tried DescribeAllEnumsAsStrings but the server then receives strings instead of the enum value which is not what we're looking for. I want to be able to submit POST actions and put enums according to their string value without having to look at the enum every time. Is there a way to display all enums as their string value in swagger instead of their int value?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |