question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation of Enums

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
domaindrivendevcommented, Jul 11, 2016

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

0reactions
icnocopcommented, May 27, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found