BAEL-5321: Change Swagger UI URL prefix (#13288)
* Initial commit for Object copy in Java * review comments commit for Object copy in Java * Initial commit for parseInt vs valueOf java * Review comments commit for parseInt vs valueOf java * Modify readme * review comments * build failure * build failure retry * build failure retry remove parseInt(java.lang.String,int,int,int) * build failure add comment * change examples * review comments * review comments 2 * review comments 3 * Initial commit for get current stacktrace * Remove old files * Name updates * Jenkins error * changes to file name * Review comments * Create unit test file * Remove unnecessary files * Update package name * BAEL-5321 Initial commit * BAEL-5321 Initial commit 2 * [BAEL-5321] review comments * [BAEL-5321] constructor * [BAEL-5321] inline
This commit is contained in:
parent
6cf8a16999
commit
d40d696e99
|
@ -0,0 +1,17 @@
|
||||||
|
package com.baeldung.springdoc.demo;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import com.baeldung.springdoc.demo.config.SpringDocSwaggerConfig;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringDocExampleApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication application = new SpringApplication(SpringDocExampleApplication.class);
|
||||||
|
//Note: SpringDocExampleApplication is the name of your main class
|
||||||
|
application.addListeners(new SpringDocSwaggerConfig());
|
||||||
|
application.run(args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.baeldung.springdoc.demo;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringFoxExampleApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringFoxExampleApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.baeldung.springdoc.demo.config;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.PropertiesPropertySource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringDocSwaggerConfig implements ApplicationListener<ApplicationPreparedEvent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(final ApplicationPreparedEvent event) {
|
||||||
|
ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put("springdoc.swagger-ui.path", swaggerPath());
|
||||||
|
environment.getPropertySources().addFirst(new PropertiesPropertySource("programmatically", props));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String swaggerPath() {
|
||||||
|
return "/myproject"; // TODO: implement your logic here.
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.springdoc.demo.config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SpringFoxSwaggerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket productApi() {
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
|
||||||
|
.paths(PathSelectors.any()).build().apiInfo(metaInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo metaInfo() {
|
||||||
|
|
||||||
|
return new ApiInfo("Sample API REST", "API REST", "1.0", "Terms of Service", null, "Apache License Version 2.0",
|
||||||
|
"https://www.apache.org/licesen.html", new ArrayList<>());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.baeldung.springdoc.demo.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class SwaggerController {
|
||||||
|
|
||||||
|
@RequestMapping("/myproject")
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
return "redirect:swagger-ui.html";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.baeldung.springdoc.demo.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.baeldung.springdoc.demo.model.Topic;
|
||||||
|
import com.baeldung.springdoc.demo.service.TopicService;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class TopicsController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TopicService topicService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/topics")
|
||||||
|
public ResponseEntity<List<Topic>> getAllTopics() {
|
||||||
|
return new ResponseEntity<>(topicService.getAlllTopics(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.baeldung.springdoc.demo.model;
|
||||||
|
|
||||||
|
public class Topic {
|
||||||
|
|
||||||
|
Integer id;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
public Topic(Integer id, String name) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.baeldung.springdoc.demo.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.baeldung.springdoc.demo.model.Topic;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TopicService {
|
||||||
|
|
||||||
|
private List<Topic> topicsList;
|
||||||
|
|
||||||
|
public TopicService(){
|
||||||
|
this.topicsList = new ArrayList<Topic>() {{
|
||||||
|
add(new Topic(1, "Topic1"));
|
||||||
|
add(new Topic(2, "Topic2"));
|
||||||
|
add(new Topic(3, "Topic3"));
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Topic> getAlllTopics(){
|
||||||
|
return topicsList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,7 @@
|
||||||
springdoc.api-docs.enabled=false
|
springdoc.api-docs.enabled=false
|
||||||
springdoc.swagger-ui.url=/api_3.yaml
|
springdoc.swagger-ui.url=/api_3.yaml
|
||||||
|
|
||||||
|
# Properties for custom Springdoc swagger-ui url
|
||||||
|
|
||||||
|
#springdoc.swagger-ui.disable-swagger-default-url=true
|
||||||
|
#springdoc.swagger-ui.path=/myproject
|
Loading…
Reference in New Issue