How to edit css/html of Swagger UI page? (Spring boot) - spring

Hi I am new to Swagger and Spring. I want to know how can I edit the swagger-ui.html page. I am using Pojo files to provide information related to parameters. What can I do to make this look better and proper? The reason I think this is happening is because I have used many Objects inside many objects. My assumption is, this should be solved using html and CSS but are getting it from swagger built-in dependencies, so can't be edited.

Assuming springdoc there is a documentation part for you: https://springdoc.org/#customizing-swagger-static-resources
You can customize swagger documentation static resources located in
META-INF/resources/webjars/swagger-ui/{swagger.version}/. The list of
resources includes: ... swagger-ui.css
And there is a code snippet.

Related

How to hide Models section from swagger UI in spring boot?

I have a spring boot project in which I have integrated the swagger, for API documentation.
Now the problem is by default it is displaying the Models section, which is a security concern. I have tried, but unable to hide it. Also have gone through this link here
How to hide the Models section in Swagger UI?
But in this also, they are refering to some index.html file, but I only have backend with no frontend. So how to achieve the same, please help.
Thanks
Found it, Look at this github link.
https://github.com/eugenp/tutorials/blob/master/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/swagger2boot/configuration/SpringFoxConfig.java

Spring Rest docs custom snippets are ignored

Setup:
Intellij IDE community
Spring Boot 2.4.0
Spring rest docs
Hi,
I use spring rest docs in all my services. The problem is that in one of them, the custom snippets are ignored and I just don't know why. Although if i'm sure that it's a mistake of mine I just can't find it.
Example snippet
One of the snippets I want to customize is the http request.
So I placed a file http-request.snippet under src/test/resources/org/springframework/restdocs/templates/asciidoctor
Content:
[source,http,options="nowrap"]
----
{{method}} {{path}} HTTP/1.1
----
So I would expect that the requestbody is not documented in this snippet but instead it is still included.
Like I said all my snippets are ignored.
UPDATE:
I've debugged StandardTemplateResourceResolver class. In fact, my templates are ignored.
I looked at the path and as you can see the method getFormatSpecificCustomTemplate should resolve my snippets but it doesn't.
Is there something else I have to configure when I add a new resource folder and I add it to the classpath?
SOLVED
I found the problem by looking at the asciidoc path in my explorer. The problem was that the creation of the direktories went wrong. Instead of creatin nested subdirectories for org/springframework/.. there was one folder with the whole directory structure as one name. Sorry for the confusion but in intellij the structure looked right.

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.

Is it possible to create Swagger documentation in separate project for Asp Web Api?

Is it possible to generate a Swagger documentation for my ASP.Net Web API in a separate project?
I created an empty project where the Swagger documentation should go. In the API project the Swagger project is referenced, but didn't work.
Than API project is load like an external assembly. The controllers was reachable, but documentation wasn't generated.
Then tried with the automatically generated XML documenatation, just to see if it will create anything, but there is no result.
After this try like to have multiple API in one Swagger documentation, Multiple API documentation in one Swagger file, wasn't work.
I also tried this:
ApiExplorer for WebAPI controllers in external assembly
https://github.com/Microsoft/aspnet-api-versioning/issues/271
On the Swagger official documentation I didn't find something that could help me with this. Neither did I find any information elsewhere if this is possible and how it needs to be done.
I use Swashbuckle 5.6.0 and ASP.Net Web API.
Yes, it is possible to generate Swagger documentation for a Web API in a separate project.
Here I have the code showing how I did it:
https://github.com/heldersepu/csharp-proj/tree/master/Swashbuckle.Sample
And here is how the swagger-ui looks like:
http://swashbucklesample.azurewebsites.net/swagger/ui/index
To be honest Nothing special about that code, it worked on the first try for me ...
But I do have some experience with Swashbuckle
If you can provide a minimal project reproducing your issue, we can help you get to the bottom of it together.

Spring Rest docs - i18n support

im currently thinking how to build REST API docs for my application with support for multiple languages. Endpoints, parameter names and return values should stay the same but the description of each REST method i want to provide in different supported languages.
Im using Spring boot, data & rest and found this docs project what seems very useful to me. Anyway, i couldn't find any informations in the docs regards the i18n topic/support.
Does anybody know if Spring REST docs support the generation of the API doc for multiple languages (in general)?
REST Docs doesn't provide any out-of-the-box support for I18N but it should be pretty straightforward to build something on top.
The main piece with which REST Docs is involved and that I think you'd want to translate are the descriptions that are included in the various snippets. Rather than hard-coding a particular description, you could look each up in a ResourceBundle:
ResourceBundle resourceBundle = ResourceBundle.getBundle("field-descriptions");
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("example", responseFields(
fieldWithPath("a").description(resourceBundle.getString("a")),
fieldWithPath("a.b").description(resourceBundle.getString("a.b")))));

Resources