ServiceStack Open API - Swagger UI not displaying enum values as dropdown

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.

Thank you, will try this

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?

Please see the attached image for details.

Kind Regards,
Sibin

Swagger-to-openapi

I’ve no idea what this is a screenshot of, these aren’t properties which are returned in the Open API json or even exist in our code base.

Hi, the screenshot is from ‘Model Schema/Example Value’ section in the SwaggerUI documentation page after the OpenAPI migration.

We are following the ‘overriding embedded resource’ method as mentioned in the documentation https://docs.servicestack.net/openapi#overriding-openapi-embedded-resources.

Kind regards,
Sibin

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.

/swagger-ui
    /css
    /fonts
    /images
    /lang
    /lib
    index.html
    swagger-ui.js

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.

You can’t reuse ServiceStack.Api.Swagger v1 assets in a ServiceStack.Api.OpenApi v2 Website:

You’ll need to copy the assets from OpenApi and re-apply your customizations again:

I’d recommend only copying what you need to customize so it’s clear exactly what has been changed in your local version.

If you only need to customize .js you can just override the patch.js or patch-preload.js files:

https://docs.servicestack.net/openapi#overriding-openapi-embedded-resources