is there way display enums string value in swagger instead of int value?
i want able submit post actions , put enums according string value without having @ enum every time.
i tried describeallenumsasstrings
server receives strings instead of enum value not we're looking for.
has solved this?
edit:
public class letter { [required] public string content {get; set;} [required] [enumdatatype(typeof(priority))] public priority priority {get; set;} } public class letterscontroller : apicontroller { [httppost] public ihttpactionresult sendletter(letter letter) { // validation not passing when using describeenumsasstrings if (!modelstate.isvalid) return badrequest("not valid") .. } // in documentation request want see string values of enum before submitting: low, medium, high. instead of 0, 1, 2 [httpget] public ihttpactionresult getbypriority (priority priority) { } } public enum priority { low, medium, high }
from the docs:
httpconfiguration .enableswagger(c => { c.singleapiversion("v1", "a title api"); c.describeallenumsasstrings(); // trick });
also, if want behavior on particular type , property, use stringenumconverter:
public class letter { [required] public string content {get; set;} [required] [enumdatatype(typeof(priority))] [jsonconverter(typeof(stringenumconverter))] public priority priority {get; set;} }
Comments
Post a Comment