mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 21:26:11 +00:00
[Spring] Add apiFirst option (#184)
* [Spring] Add apiFirst option * Git diff to see what's wrong * Git diff to see what's wrong * Update bin/ensure-up-to-date * Run bin/ensure-up-to-date
This commit is contained in:
committed by
William Cheng
parent
f4c66d9e53
commit
7a1945e154
@@ -9,4 +9,4 @@ This server was generated by the [OpenAPI Generator](https://openapi-generator.t
|
||||
The underlying library integrating OpenAPI to Spring-MVC is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
You can view the server in swagger-ui by pointing to
|
||||
http://localhost:8002/v2/swagger-ui.html
|
||||
http://localhost:8002/v2/
|
||||
@@ -94,7 +94,6 @@
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@@ -112,7 +111,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
@@ -130,13 +128,13 @@
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
@@ -146,9 +144,9 @@
|
||||
<slf4j-version>1.7.21</slf4j-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<springfox-version>2.7.0</springfox-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
<jackson-version>2.9.5</jackson-version>
|
||||
<jackson-threetenbp-version>2.8.4</jackson-threetenbp-version>
|
||||
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
|
||||
<spring-version>4.3.9.RELEASE</spring-version>
|
||||
</properties>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@@ -18,9 +19,9 @@ import java.util.List;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "org.openapitools.api")
|
||||
@ComponentScan(basePackages = {"org.openapitools.api", "org.openapitools.configuration"})
|
||||
@EnableWebMvc
|
||||
@PropertySource("classpath:openapi.properties")
|
||||
@PropertySource("classpath:application.properties")
|
||||
@Import(OpenAPIDocumentationConfig.class)
|
||||
public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
@@ -57,18 +58,26 @@ public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
return new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
Reference in New Issue
Block a user