I found this nice type-safe enum pattern, and i think is very cool.
The class does have only public static properties and a private constructor
, and can implicitly inferred from a string
. I'm using it as a property of my model which get model-binded
correctly in asp.net core web api controller when I pass a string
. Passing invalid string
values also work fine as the binder
is able to set ModelSate=false
. I have something in this line:
class Mymodel
{
public TypeSafeEnum TypeSafeEnum { get; set; }
public string Name { get; set; }
// the rest of props
}
Throwing in some swagger api documentation, the property is seen as an object, hence swagger trying to help will give example input model as:
{
"typeSafeEnum": {},
"name": "string",
// the rest
}
The swagger just see an object with no public properties.
Is there a form of telling swagger that I'm actually expecting a string
? or will I be deceiving my clients as not all string values are valid? But again how do I provide meaningful hint?