ServiceStack: No /swagger-ui/index.html

2019-07-14 07:54发布

问题:

I am using ServiceStack for my custom service, in stand alone mode without IIS.

I would like to add documentation for my services beyond what /metadata does. I thought to try the Swagger plug in.

I have added the plug-in command to my Config

        public override void Configure(Funq.Container container)
        {
            SetConfig(new EndpointHostConfig()
            {
                DefaultRedirectPath = "index.html",
                DebugMode = true,
                WriteErrorsToResponse = true,

                CustomHttpHandlers =
                {
                    { HttpStatusCode.Unauthorized, new AuthorizationErrorHandler() },
                    { HttpStatusCode.Forbidden, new AuthorizationErrorHandler() },
                    { HttpStatusCode.NotFound, new AuthorizationErrorHandler() }
                }

            });

            // For automatic generation of documentation to APIs
            Plugins.Add(new SwaggerFeature());
        }

The existing services continue to work, but attempting to access

/swagger-ui/index.html

gives the not found error. Is there an additional step not clearly documented at

https://github.com/ServiceStack/ServiceStack/wiki/Swagger-API

Do I have to actually set up this page myself? If so, how?

回答1:

After more research, using the servicestack.api.swagger package only installs the /resource service to query the API. It does not include any client-side resources.

To get the client-side UI, you have to download the files from the Swagger UI project on Github, and install the dist directory resources yourself.



回答2:

Adding the ServiceStack.Api.Swagger NuGet package should include all the client side resources you need. Try updating the NuGet package as all the client side resources you need should already be in /swagger-ui