Documentation of Enums
See original GitHub issueI have a model with an enum.
public class Model
{
///<summary>Current State</summary>
public StatusValues Status {get;set;}
}
This enum is annotated with xml-comments.
///<summary>Possible state values</summary>
public enum StatusValues
{
///<summary>This is On</summary>
On,
///<summary>This is Off</summary>
Off,
///<summary>We simply don't know</summary>
Unknown
}
This results in the following json info:
"Status":{
"description":"Current State",
"enum":["On","Off","Unknown"],
"type":"string"
}
I would like to see the annotations of the enumvalues in the swagger json. There is a proposal on the Open Spec to support this, but nothing official. For now I would be happy to have a way to add the descriptions of the enumvalues to the description of the model property. Like this, for example:
"Status":{
"description":"Current State
* `On` - This is On
* `Off` - This is Off
* `Unknown` - We simply don't know",
"enum":["On","Off","Unknown"],
"type":"string"
}
I’ve played around with all kinds of filters, but the only thing I can find to do something like this is using MapType<>
for each enum individually. But that doesn’t really scale.
Am I missing something, or do you accept a pull request to add this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Enum Types - Learning the Java Language
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must...
Read more >enum — Support for enumerations
is a set of symbolic names (members) bound to unique values · can be iterated over to return its canonical (i.e. non-alias) members...
Read more >How to Javadoc a Class's Individual Enums
From Paŭlo Ebermann : The enum is a separate class. You can't include its full documentation in the enclosing class (at least, without...
Read more >Enumerations | Documentation - Swift.org
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe...
Read more >TypeScript: Handbook - Enums
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Under the hood, IncludeXmlComments just wires up an operation filter and a schema filter. So, if you apply your Schema filter after that call, it should happen in the desired order.
However, Schema Filters are currently only applied to “object” schema’s and therefore won’t execute against an “enum” schema. There is a PR that’s close to being merged that will apply schema filters everywhere: https://github.com/domaindrivendev/Swashbuckle/pull/799
Once this is in place, your task should be fairly straightforward
As a work-around, I was able to re-use the code here: https://www.codeproject.com/Articles/5300099/Description-of-the-Enumeration-Members-in-Swashbuc