Why springdoc swagger-ui returns page with empty array []? - spring-boot

When I run locally my Spring Boot application with added dependencies springdoc-openapi-ui, I expect to get generated swagger api form for rest methods at url
http://localhost:55555/swagger-ui/index.html, but instead I get response with empty array []. But if I open http://localhost:55555/v3/api-docs, it shows openapi specification for rest methods.
There is no warnings in application log. How can I troubleshoot this library?
P.S. Swagger api form was working shortly before this moment. When problem had been occured, I removed any related configuration properties and beans, but the problem remained

Related

Open API (Swagger) non working in Spring Boot when adding context path

I have a Spring Boot application exposing REST services that are easily called on addresses like
http://localhost:8080/<controller_mapping>/<service_mapping>.
I've been asked to modify my settings in order to add a context path and have my services to respond on
http://localhost:8080//gesev-mensa/<controller_mapping>/<service_mapping>.
Thus I edited my application.properties adding
server.servlet.context-path=/gesev-mensa
Everything works but I can't call Swagger on old address
http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config#/
I get the error Failed to load remote configuration
As suggested, I tried to add property
springdoc.swagger-ui.path=/gesev-mensa/swagger-ui/index.html
but problem persists.
I guess Swagger should be reachable at
http://localhost:8080/gesev-mensa/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config#/
but that doesn't work.
Any hint?
Thanks for support.
Try removing
springdoc.swagger-ui.path=/gesev-mensa/swagger-ui/index.html
from your properties,
And your swagger will be available in
http://localhost:8080/gesev-mensa/swagger-ui/index.html
As per your current configuration with,
springdoc.swagger-ui.path=/gesev-mensa/swagger-ui/index.html
Swagger will be available in
http://localhost:8080/gesev-mensa/gesev-mensa/swagger-ui/index.html

Custom swagger documentation/ Where is my swagger setup?

I have a jhipster based Spring project, which uses yarn/angular on the front end, and Spring on the back. I am with trying to figure out how to customize the swagger page. Currently it auto-populates new API's using swagger-ui, which is great, but I needed to add more custom info to those API's, hence my problem.
But I'm confused on what's running swagger. It looks like there's a node package called swagger-ui-dist and I also see a src/main/webapp folder with a swagger-ui folder, containing an index.html page.
I think what I pretty much want is to replace the current swagger-ui auto setup, with swagger that reads a file that I can create online using Swagger editor.
Apologies, for what I hope are simple questions. I'm brand new at swagger and npm/yarn.
Thanks
So after a bit more research, I found you could create your own OpenAPI doc, but an easier method in Spring is to annotate the endpoint methods with the #APIOperation annotation. There are other swagger specific annotations as well.
In the parameters, you can give value="", notes="" and a number of other customized values that will clarify what your API does in Swagger. Then swagger auto fills it in when bringing up your swagger page.
I hope that helps anyone with the same issue I had.

springfox-swagger : model with SnakeCaseStrategy support

I'm currently using Springfox Swagger to document my spring boot application with a Java config.
When I add
#JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
on my model class, and execute the application from swagger ui, its giving me null pointer exception.
But code runs if you try to run from postman or some java client.
I want all my model attributes in snake case. Looks like swagger is not able to serialize/deserialize the object. Please let me know if there is any workaround

Swagger shows wrong id field using Spring Data Rest

I'm using Spring Boot + Spring DATA REST and Swagger (Springfox 2.7.0). Spring DATA REST follows HATEOAS principles, so id field should never be present in return resources.
In GET methods this works fine but in POST methods the form show an id parameter I don't understand where it comes from.
This is the screenshot of the Swagger ui. Like you see, the form contains an id parameter of type path that is not present in the model definition.
I'm sure it is not needed, in fact doing a request via Postman, it works without set id param.
Also in swagger everything works fine, filling id param with a random value.
Is it an incompatibility between Spring DATA REST and Swagger or I should set something more?
I followed instructions here:http://springfox.github.io/springfox/docs/current/#support-for-spring-data-rest
=================== UPDATE ==============================
This issue is resolved in SpringFox version > 2.7.0.
Here the link to the bug: https://github.com/springfox/springfox/issues/1839

swagger2 for springboot microservice do no produce response on ui

I created one micro service with spring boot, I don't have resource folder and i wanted to add swagger support. So I followed as per document
So
Added swagger dependency.
Added docker class as it is
Added swagger's ui dependency
Results
http://localhost:port/myservice/v2/api-docs ->
Response is as per expectation.
http://localhost:port/myservice/v2/api-docs ->
Response is as per expectation.
But
http://localhost:port/myservice/swagger-ui.html ->
Not expected response, on browser console i am getting error
GET http://localhost:port/myservice/configuration/ui 404 (Not Found)
As its microservice, I don't have #EnableWebMvc class.
What Am I missing ?
I had the same problem. Downgrading springfox-swagger-ui to 2.2.2 fixed my problem (as mentioned in the comments by sailor.

Resources