I have recently upgraded my ServiceStack libraries from 5.10.4 to 6.5.0 and implemented Open API as specified in the documentation. But my Enum properties are displayed as Textbox instead of Dropdown in the /swagger-ui page.
This was working as expected previously when I was using ‘ServiceStack.Api.Swagger’ instead of ‘ServiceStack.Api.OpenApi’.
Can someone please help me in this?
Thanks and Regards, Sibin
This is the code I am using:
// Configuration
Plugins.Add(new OpenApiFeature());
// DTO
[Route("my-route", "GET", Summary = "My summary")]
public class MyClass: IReturn<MyResponse>
{
[ApiMember(Name = "Alphabet", Description = "Alphabet",
ParameterType = "path", DataType = "string", IsRequired = true)]
[ApiAllowableValues("Alphabet", typeof(Alphabets))]
public string Alphabet { get; set; }
}
// Enum
public enum Alphabets
{
A,
B,
C,
D
}
This should now be resolved in the latest v6.5.1+ that’s now available on MyGet.
Alternatively you can change your DTO to have an Enum property, which also doesn’t require an [ApiAllowableValues] attribute, e.g:
[Route("/my-route", "GET", Summary = "My summary")]
public class MyClass: IReturn<MyResponse>
{
[ApiMember(Name = "Alphabet", Description = "Alphabet",
ParameterType = "path", DataType = "string", IsRequired = true)]
public Alphabets Alphabet { get; set; }
}
If you haven’t already, checkout API Explorer that’s built into ServiceStack v6+ which you can view from /ui or a specific API from /ui/{RequestDto} e.g. /ui/MyClass.
Hi, I have noticed few issues in the Swagger UI documentation after the Open API migration.
Default value of string properties changed from blank string to ‘string’ and also the default value of boolean changed from false to true. Is there a way to fix this issues?
I’m still no closer to knowing what you’re talking about, other than you’re overriding the built-in Swagger UI assets to customize your local version of Swagger UI, what are the customizations?
What “Open API migration” are you referring to? Which Swagger UI documentation are you referring to exactly?
As mentioned in your documentation we are simply copied the below swagger resources in our application and made some customization in terms of styling.
The above mentioned issues happening in our SwaggerUI documentation page after we moved from ‘ServiceStack.Api.Swagger’ to ‘ServiceStack.Api.OpenApi’. Hope you get my point.