Changing Name and Description endpoint in Swagger-ui - spring

I am using Spring boot and Spring Data Rest to implement my Rest API. To document it, I have been using Swagger, with these maven dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>2.6.1</version>
</dependency>
I would like to change and customize a bit my Swagger UI page. I want to change the name and the description it appears in the html page, concretely these names highlighted in red in the screenshot, but nothing works.
I've been trying adding the #Api annotation to my entities and repositories classes/interfaces, but nothing works.
Any idea about how to customize it?
Thanks!

Use the #Api annotation with tags and description.
#Api(description="Device APIs", tags = "Device")
Please note that description is deprecated but it works.

Related

Getting "Finished Loading Resource Information. Rendering Swagger UI..." on loading swagger after migration from spring to sprinboot

We just migrated our application from Spring to Sprinboot (2.7.0). whenever i load swagger, all the apis dont get loaded and i get this line "Finished Loading Resource Information. Rendering Swagger UI..." on the top.
But http://host:port/v2/api-docs loads all the apis.
earlier we have below swagger related dependencies in our pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${version.io.springfox}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.6.8</version>
</dependency>
dependencies. I tried with that, i got same issue.
Later i tried adding springfox-boot-starter dependency and commenting out specific swagger based spring dependencies but no luck. I tried to search for a solution but couldnt find anything concrete.
Any idea why this is happening?

SpringMVC Form Validation doesn't work properly

I have an issue with springMVC Form Validation .. I have an example in a project using maven and the same with gradle and when running each one , validation with gradle example work proberly but not working proberly with maven.
any help please?
I have attached the two projects
https://drive.google.com/drive/folders/1BXEuBebHecHagYLGvuzX0yqBgw6u_t1C?fbclid=IwAR24x9D3oCtcp_awdX8sb7CEm_uK2Ngx93vMTPuy_-3gIMpJIl14TctLANo
thanks , the problem wasn't from org.jetbrains.annotations.NotNull;
sometimes when you apply auto import , it make a problems. the problem is because I missed Hibernate Validation from my POM file so , auto import include this
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
which give a logical error (the validation doesn't work and go to next page even if condition not valid)
so the solution is to include this
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
and don't apply auto import in intellij
thanks

WhiteLabel error page while trying to access swagger-ui.html using springfox configuration

I am trying to generate Swagger documentation from a springboot project using Springfox and following https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api documentation.
Initially I got the error "Full authorization is required to access the resource" since I am using OAuth2 in my application. I changed the configuration to permit all the requests ending with /swagger-ui.html.
Now I have been getting "WhiteLabel error page - This application has no explicit mapping for /error" while trying to access /swagger-ui.html on my local.
I went through various posts but none of the solutions worked for me - I am not using #webmvcconfiguration which can interfere.
Can anyone help?
For Swagger 3.0, The URL is changed to
http://localhost:8080/swagger-ui/index.html
Remove the v2 dependencies from your pom.xml or comment them out.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Add the springfox-boot-starter
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Change the URL in your browser to:
http://localhost:8080/swagger-ui/index.html
The general form for the URL is:
http://host/context-path/swagger-ui/index.html
OR
http://host/context-path/swagger-ui/
For more info check this link that leads to the relevant documentation:
https://springfox.github.io/springfox/docs/snapshot/#changes-in-swagger-ui
This is how I solved my problem. Here is my detailed code, if someone want to look.
https://github.com/xbox2204/SpringBoot-JPA-Swagger
Now, I used 3.0.0-SNAPSHOT and a latest spring-boot starter project I created from here:
https://start.spring.io/
My pom.xml, I added following dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
In my application.properties, I added following:
spring.resources.add-mappings=true
In my SpringBoot Main/Runner class, I added these annotations
#EnableWebMvc
#EnableSwagger2
#SpringBootApplication
My Docket returning function looked like this
#Bean
public Docket productApi() {
Contact contact =new Contact(
"Vineet Mishra",
"https://github.com/xbox2204",
"whatwillyoudo#withmyemail.com"
);
ApiInfo apiInfo= new ApiInfoBuilder().title("VINEET SPRING-BOOT API")
.description("Spring-Boot for all")
.termsOfServiceUrl("jUST CHILL!!!")
.contact(contact)
.licenseUrl("something#something.com").version("1.0").build();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.build();
}
Finally, I accessed my swagger-ui from
http://localhost:8080/swagger-ui/index.html#
Image of final result
The swagger-ui.html page makes a number of calls to get all the details. If you use your browser's dev tools (usually just press F12 to open) you will see failing requests in the network tab. You'll need to permit requests to
"/v2/api-docs",
"/swagger-resources/**",
"/swagger-ui.html**",
"/webjars/**"
There's some info in the springfox docs , do a find for 'security' or 'authorization'

BootsFaces annotation throwing errors

I have just started with BootsFaces and copied a showcase from the web.
I have added BootsFaces-OSP-1.0.2-dist.jar to my eclipse project with JSF 2.1
Problem I am facing is two annotations #Size and #NotEmpty is throwing error. I can guess its a setup issue, can anybody help?
With so little information, I can only guess. I suppose you're referring to compiler errors. Did you add the validation API and the hibernate validator?
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.2.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
This is the complete list of jars you have to add to run our showcase:

Spring Data JPA Error for 1.7.0.M1 query lookup strategy Exception

I was trying to Integrate Spring Data JPA with custom queries added in my repository.The following error made me crazy
"You have defined query method in the repository
but you don't have no query lookupstrategy defined.
The infrastructure apparently does not support query methods!"
Can Anyone tell me how to solve this?
Upgrade the spring-data-commons dependency to 1.9.0.RELEASE.
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
It was solved when downgraded to 1.6.2.RELEASE
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<!-- <version>1.7.0.M1</version> -->
<version>1.6.2.RELEASE</version>
</dependency>

Resources