Swagger UI not exposing endpoints - asp.net-web-api

We have 3 component in .Net Web Api project.
Framework(ClassLib): Contains Controller Base, filters and
dependency injection
DevHost(WebAPI app): Act as a entry point of web API application
API(ClassLib): Contains controllers, models,
WebApiConfig and swagger config
Hence, SwaggerConfig class is resides in API library. Whenever I am trying to call localhost/swagger/ui/index , it's displaying swagger documentation page without endpoints.
Is there any way, so we can specify custom route object from where Swagger should expose endpoints?
Note: SwaggerConfig and rest part is configure correctly.

Related

We use Swagger UI to provide certain functionality in microservices. Which bean should we use?

We use Swagger UI to provide certain functionality in microservices.
Which bean should we use?
Swagger Context Provider
Swagger Application Provider
Swagger Resources Provider

Adding swagger UI for spring cloud gateway service

I need help in adding swagger ui for my spring cloud gateway microservice.
My spring cloud gateway service is routing the request to another microservice which already has swagger ui enabled since it has a controller layer
But since my spring cloud gateway service doesn't have any #Controller class and all the routes are defined in a RouteConfig class which doesn't do much except routing the request to actual service

Spring-boot Spring-MVC application with jsp views and Swagger-ui

We have a Spring-boot application that has jsps for view. We are writing REST services to get the data from back-end.
Since the service needs to return a view, it is annotated with #Controller.
How can I implement it such that I can also test these services with Swagger but be able to return the view string from the REST endpoint?
Also examples mention to use #RestController, which I cannot use because of the need to return a view.
Thank you

Using basic auth with the apiDiscovery feature in Liberty

I am using the apiDiscovery-1.0 feature in Liberty in order to expose the Swagger UI for my REST APIs. However, my REST APIs are secured using Basic Auth and the Authorize button is not being displayed in the UI exposed by the apiDiscovery feature in Liberty. Is this supported with the apiDiscovery feature?
The version of Liberty that I am using is as follows:
product = WebSphere Application Server 17.0.0.2 (wlp-1.0.17.cl170220170523-1818)
If you are using annotations (JAXRS + Swagger v2), please note that you can only reference security definitions from within your annotated code - to actually declare them you will have to use a Swagger v2 stub document (inside META-INF/stub).
Check this sample.
In there we declare the security definition in the stub and then reference it from the annotation.
This is due to a limitation in the Swagger v2 annotation library that doesn't allow for security declarations from within annotations. This is something we're working to fix for OpenAPI v3.

Sharing of a view among microservies

I'm splitting up a monolith web service into several microservices using spring boot. To reduce duplicated code I extracted shared parts in a maven module that is used in the different microservices.
The monolith application had a healthcheck page that showed various information about the state of the service and some debbuging infos. It is implemented with Spring MVC and jsp.
I'd like to use this view in each of the microservices. Whats the best way to do this without duplicating the view/controller?
I was thinking of adding a web module to the shared maven project that contains the controller, view, spring mvc settings,...
But I'm not sure if it is good to have two web modules in one microservice.
Have you considered using spring boot actuator to retrieve health (and more) application information?
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready
You could then have another microservice that retrieves that information from each of your services, or just simply check it on then hitting the different endpoints (/health, /env, etc.).
UPDATE:
If you have you custom health logic you can even implement your own actuator endpoint for it. Furthermore, you can create your own library to reuse it in all your microservices:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-customizing-endpoints-programmatically
46.4 Adding custom endpoints
If you add a #Bean of type Endpoint then it will automatically be exposed over JMX and HTTP (if there is an
server available). An HTTP endpoints can be customized further by
creating a bean of type MvcEndpoint. Your MvcEndpoint is not a
#Controller but it can use #RequestMapping (and #Managed*) to expose
resources.
[Tip]
If you are doing this as a library feature consider adding a
configuration class annotated with #ManagementContextConfiguration to
/META-INF/spring.factories under the key
org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration.
If you do that then the endpoint will move to a child context with all
the other MVC endpoints if your users ask for a separate management
port or address. A configuration declared this way can be a
WebConfigurerAdapter if it wants to add static resources (for
instance) to the management endpoints.

Resources