forked from loafle/openapi-generator-original
[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:
parent
f4c66d9e53
commit
7a1945e154
@ -29,8 +29,11 @@ sleep 5
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "UNCOMMITTED CHANGES ERROR"
|
||||
echo "There are uncommitted changes in working tree after execution of 'bin/ensure-up-to-date'"
|
||||
echo "Perform git diff"
|
||||
git --no-pager diff
|
||||
echo "Perform git status"
|
||||
git status
|
||||
echo "Please run 'bin/ensure-up-to-date' locally and commit changes"
|
||||
echo "Please run 'bin/ensure-up-to-date' locally and commit changes (UNCOMMITTED CHANGES ERROR)"
|
||||
exit 1
|
||||
else
|
||||
echo "Git working tree is clean"
|
||||
|
@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
@ -41,12 +42,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, OptionalFeatures {
|
||||
@ -69,6 +67,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String SPRING_CLOUD_LIBRARY = "spring-cloud";
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String OPENAPI_DOCKET_CONFIG = "swaggerDocketConfig";
|
||||
public static final String API_FIRST = "apiFirst";
|
||||
|
||||
protected String title = "OpenAPI Spring";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
@ -85,6 +84,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean openapiDocketConfig = false;
|
||||
protected boolean apiFirst = false;
|
||||
protected boolean useOptional = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
@ -114,6 +114,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers.", implicitHeaders));
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_DOCKET_CONFIG, "Generate Spring OpenAPI Docket configuration class.", openapiDocketConfig));
|
||||
cliOptions.add(CliOption.newBoolean(API_FIRST, "Generate the API from the OAI spec at server compile time (API first approach)", apiFirst));
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters", useOptional));
|
||||
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application using the SpringFox integration.");
|
||||
@ -145,9 +146,19 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
@Override
|
||||
public void processOpts() {
|
||||
|
||||
List<Pair<String,String>> configOptions = additionalProperties.entrySet().stream()
|
||||
.filter(e -> !Arrays.asList(API_FIRST, "hideGenerationTimestamp").contains(e.getKey()))
|
||||
.filter(e -> cliOptions.stream().map(CliOption::getOpt).anyMatch(opt -> opt.equals(e.getKey())))
|
||||
.map(e -> Pair.of(e.getKey(), e.getValue().toString()))
|
||||
.collect(Collectors.toList());
|
||||
additionalProperties.put("configOptions", configOptions);
|
||||
|
||||
// Process java8 option before common java ones to change the default dateLibrary to java8.
|
||||
System.out.println("----------------------------------");
|
||||
if (additionalProperties.containsKey(JAVA_8)) {
|
||||
System.out.println("has JAVA8");
|
||||
this.setJava8(Boolean.valueOf(additionalProperties.get(JAVA_8).toString()));
|
||||
additionalProperties.put(JAVA_8, java8);
|
||||
}
|
||||
if (this.java8 && !additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
setDateLibrary("java8");
|
||||
@ -232,6 +243,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setOpenapiDocketConfig(Boolean.valueOf(additionalProperties.get(OPENAPI_DOCKET_CONFIG).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(API_FIRST)) {
|
||||
this.setApiFirst(Boolean.valueOf(additionalProperties.get(API_FIRST).toString()));
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
@ -255,16 +270,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
if (!this.interfaceOnly) {
|
||||
if (library.equals(SPRING_BOOT)) {
|
||||
if (!this.reactive) {
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("openapi2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "OpenAPI2SpringBoot.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
}
|
||||
if (library.equals(SPRING_MVC_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("webApplication.mustache",
|
||||
@ -275,8 +284,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIUiConfiguration.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.properties",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "openapi.properties"));
|
||||
}
|
||||
if (library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("apiKeyRequestInterceptor.mustache",
|
||||
@ -290,20 +297,19 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
} else {
|
||||
apiTemplateFiles.put("apiController.mustache", "Controller.java");
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("apiResponseMessage.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("notFoundException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
|
||||
if (!this.reactive) {
|
||||
supportingFiles.add(new SupportingFile("apiOriginFilter.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
if (!this.reactive && !this.apiFirst) {
|
||||
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIDocumentationConfig.java"));
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache",
|
||||
("src/main/resources").replace("/", java.io.File.separator), "openapi.yaml"));
|
||||
}
|
||||
}
|
||||
} else if (this.openapiDocketConfig && !library.equals(SPRING_CLOUD_LIBRARY) && !this.reactive) {
|
||||
} else if (this.openapiDocketConfig && !library.equals(SPRING_CLOUD_LIBRARY) && !this.reactive && !this.apiFirst) {
|
||||
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIDocumentationConfig.java"));
|
||||
}
|
||||
@ -313,6 +319,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiUtil.java"));
|
||||
}
|
||||
|
||||
if (this.apiFirst) {
|
||||
apiTemplateFiles.clear();
|
||||
modelTemplateFiles.clear();
|
||||
}
|
||||
|
||||
if ("threetenbp".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("customInstantDeserializer.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "CustomInstantDeserializer.java"));
|
||||
@ -344,6 +355,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
additionalProperties.put(RESPONSE_WRAPPER, "Callable");
|
||||
}
|
||||
|
||||
if(!this.apiFirst && !this.reactive) {
|
||||
additionalProperties.put("useSpringfox", true);
|
||||
}
|
||||
|
||||
|
||||
// Some well-known Spring or Spring-Cloud response wrappers
|
||||
switch (this.responseWrapper) {
|
||||
case "Future":
|
||||
@ -565,6 +581,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateYAMLSpecFile(objs);
|
||||
if(library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
List<CodegenSecurity> authMethods = (List<CodegenSecurity>) objs.get("authMethods");
|
||||
if (authMethods != null) {
|
||||
@ -659,6 +676,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.openapiDocketConfig = openapiDocketConfig;
|
||||
}
|
||||
|
||||
public void setApiFirst(boolean apiFirst) {
|
||||
this.apiFirst = apiFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.DateTimeUtils;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
@ -205,7 +205,7 @@ public class CustomInstantDeserializer<T extends Temporal>
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
|
@ -0,0 +1,88 @@
|
||||
package {{configPackage}};
|
||||
|
||||
{{^useSpringfox}}
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.Resource;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.stereotype.Controller;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
{{/reactive}}
|
||||
|
||||
{{^useSpringfox}}
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
import java.net.URI;
|
||||
{{/reactive}}
|
||||
{{^useSpringfox}}
|
||||
import java.nio.charset.Charset;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
{{/reactive}}
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
{{^useSpringfox}}
|
||||
private static YAMLMapper yamlMapper = new YAMLMapper();
|
||||
|
||||
@Value("classpath:/openapi.yaml")
|
||||
private Resource openapi;
|
||||
|
||||
@Bean
|
||||
public String openapiContent() throws IOException {
|
||||
try(InputStream is = openapi.getInputStream()) {
|
||||
return StreamUtils.copyToString(is, Charset.defaultCharset());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi")
|
||||
@ResponseBody
|
||||
public String openapiYaml() throws IOException {
|
||||
return openapiContent();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.json", produces = "application/json")
|
||||
@ResponseBody
|
||||
public Object openapiJson() throws IOException {
|
||||
return yamlMapper.readValue(openapiContent(), Object.class);
|
||||
}
|
||||
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> index() {
|
||||
return route(
|
||||
GET("/"),
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}")).build()
|
||||
);
|
||||
}
|
||||
{{/reactive}}
|
||||
{{^reactive}}
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}";
|
||||
}
|
||||
{{/reactive}}
|
||||
|
||||
|
||||
}
|
@ -8,13 +8,15 @@ This server was generated by the [OpenAPI Generator](https://openapi-generator.t
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
|
||||
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
{{#useSpringfox}}
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
{{/useSpringfox}}
|
||||
Start your server as an simple java application
|
||||
|
||||
{{^reactive}}
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:{{serverPort}}/
|
||||
|
||||
{{/reactive}}
|
||||
Change default port value in application.properties{{/interfaceOnly}}{{#interfaceOnly}}
|
||||
|
@ -1,4 +1,6 @@
|
||||
{{#useSpringfox}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/useSpringfox}}
|
||||
server.port={{serverPort}}
|
||||
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
@ -4,7 +4,25 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
{{^reactive}}
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
{{^java8}}
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
{{/java8}}
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
{{/reactive}}
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
|
||||
@ -30,4 +48,25 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer webConfigurer() {
|
||||
return new Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer{{^java8}}Adapter{{/java8}}() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
{{^useSpringfox}}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/useSpringfox}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
{{^reactive}}
|
||||
{{#useSpringfox}}
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
{{/reactive}}
|
||||
{{/useSpringfox}}
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -33,6 +33,38 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{#apiFirst}}
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>{{{generatorVersion}}}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>src/main/resources/openapi.yaml</inputSpec>
|
||||
<generatorName>spring</generatorName>
|
||||
<apiPackage>{{{apiPackage}}}</apiPackage>
|
||||
<modelPackage>{{{modelPackage}}}</modelPackage>
|
||||
<generateSupportingFiles>false</generateSupportingFiles>
|
||||
{{#modelNamePrefix}}
|
||||
<modelNamePrefix>{{{.}}}</modelNamePrefix>
|
||||
{{/modelNamePrefix}}
|
||||
{{#modelNameSuffix}}
|
||||
<modelNameSuffix>{{{.}}}</modelNameSuffix>
|
||||
{{/modelNameSuffix}}
|
||||
<configOptions>
|
||||
{{#configOptions}}
|
||||
<{{left}}>{{right}}</{{left}}>
|
||||
{{/configOptions}}
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{/apiFirst}}
|
||||
</plugins>
|
||||
{{/interfaceOnly}}
|
||||
</build>
|
||||
@ -41,7 +73,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web{{#reactive}}flux{{/reactive}}</artifactId>
|
||||
</dependency>
|
||||
{{^reactive}}
|
||||
{{#useSpringfox}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@ -53,43 +85,47 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
{{/useSpringfox}}
|
||||
{{^useSpringfox}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.14</version>
|
||||
</dependency>
|
||||
{{/reactive}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{#withXml}}
|
||||
|
||||
<!-- XML processing: Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
|
||||
{{/withXml}}
|
||||
{{#java8}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#joda}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#threetenbp}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<version>2.8.4</version>
|
||||
</dependency>
|
||||
{{/threetenbp}}
|
||||
{{#useBeanValidation}}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ThreeTenModule.class)
|
||||
ThreeTenModule threeTenModule() {
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
return module;
|
||||
}
|
||||
}
|
@ -6,7 +6,9 @@ Spring MVC Server
|
||||
## Overview
|
||||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. This is an example of building a OpenAPI-enabled server in Java using the Spring MVC framework.
|
||||
|
||||
{{#useSpringfox}}
|
||||
The underlying library integrating OpenAPI to Spring-MVC is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
{{/useSpringfox}}
|
||||
You can view the server in swagger-ui by pointing to
|
||||
http://localhost:{{serverPort}}{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/swagger-ui.html
|
||||
http://localhost:{{serverPort}}{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/
|
@ -0,0 +1,3 @@
|
||||
{{#useSpringfox}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/useSpringfox}}
|
@ -8,9 +8,12 @@ import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
{{#useSpringfox}}
|
||||
import org.springframework.context.annotation.Import;
|
||||
{{/useSpringfox}}
|
||||
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;
|
||||
@ -26,10 +29,12 @@ import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "{{apiPackage}}")
|
||||
@ComponentScan(basePackages = {"{{apiPackage}}", "{{configPackage}}"})
|
||||
@EnableWebMvc
|
||||
@PropertySource("classpath:openapi.properties")
|
||||
@PropertySource("classpath:application.properties")
|
||||
{{#useSpringfox}}
|
||||
@Import(OpenAPIDocumentationConfig.class)
|
||||
{{/useSpringfox}}
|
||||
public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
|
||||
@ -63,20 +68,42 @@ public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
if (!registry.hasMappingForPattern("/**")) {
|
||||
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
{{^useSpringfox}}
|
||||
if (!registry.hasMappingForPattern("/swagger-ui/**")) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/useSpringfox}}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
{{#threetenbp}}
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
{{/threetenbp}}
|
||||
return new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
{{#threetenbp}}
|
||||
.modulesToInstall(module)
|
||||
{{/threetenbp}}
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,39 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{#apiFirst}}
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>{{{generatorVersion}}}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>src/main/resources/openapi.yaml</inputSpec>
|
||||
<generatorName>spring</generatorName>
|
||||
<library>spring-mvc</library>
|
||||
<apiPackage>{{{apiPackage}}}</apiPackage>
|
||||
<modelPackage>{{{modelPackage}}}</modelPackage>
|
||||
<generateSupportingFiles>false</generateSupportingFiles>
|
||||
{{#modelNamePrefix}}
|
||||
<modelNamePrefix>{{{.}}}</modelNamePrefix>
|
||||
{{/modelNamePrefix}}
|
||||
{{#modelNameSuffix}}
|
||||
<modelNameSuffix>{{{.}}}</modelNameSuffix>
|
||||
{{/modelNameSuffix}}
|
||||
<configOptions>
|
||||
{{#configOptions}}
|
||||
<{{left}}>{{right}}</{{left}}>
|
||||
{{/configOptions}}
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{/apiFirst}}
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
@ -96,7 +129,7 @@
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
|
||||
{{#useSpringfox}}
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@ -114,18 +147,33 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{^useSpringfox}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{#withXml}}
|
||||
|
||||
<!-- XML processing: Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
{{/withXml}}
|
||||
{{#java8}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
@ -133,7 +181,6 @@
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#joda}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
@ -141,7 +188,6 @@
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#threetenbp}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
@ -178,9 +224,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>
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
|
@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
@ -35,7 +35,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
|
@ -1,16 +1,19 @@
|
||||
package {{configPackage}};
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
#server.port=8090
|
@ -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>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
#server.port=8090
|
@ -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,13 +111,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
@ -145,16 +137,16 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>1.7</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<jetty-version>9.2.15.v20160210</jetty-version>
|
||||
<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>
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.DateTimeUtils;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
@ -205,7 +205,7 @@ public class CustomInstantDeserializer<T extends Temporal>
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
|
@ -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";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -40,9 +40,6 @@ public class OpenAPIDocumentationConfig {
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.api"))
|
||||
.build()
|
||||
.pathProvider(new BasePathAwareRelativePathProvider(servletContext, basePath))
|
||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)
|
||||
.apiInfo(apiInfo());
|
||||
|
@ -9,6 +9,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;
|
||||
@ -22,9 +23,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 = { "/" };
|
||||
@ -61,18 +62,31 @@ 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()
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
return new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.modulesToInstall(module)
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerDocumentationConfig {
|
||||
|
||||
ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("Swagger Petstore")
|
||||
.description("This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\")
|
||||
.license("Apache-2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
|
||||
.termsOfServiceUrl("")
|
||||
.version("1.0.0")
|
||||
.contact(new Contact("","", "apiteam@swagger.io"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket customImplementation(){
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.api"))
|
||||
.build()
|
||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)
|
||||
.apiInfo(apiInfo());
|
||||
}
|
||||
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "org.openapitools.api")
|
||||
@EnableWebMvc
|
||||
@PropertySource("classpath:openapi.properties")
|
||||
@Import(SwaggerDocumentationConfig.class)
|
||||
public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
|
||||
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
|
||||
"classpath:/META-INF/resources/", "classpath:/resources/",
|
||||
"classpath:/static/", "classpath:/public/" };
|
||||
|
||||
private static final String[] RESOURCE_LOCATIONS;
|
||||
static {
|
||||
RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
|
||||
+ SERVLET_RESOURCE_LOCATIONS.length];
|
||||
System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
|
||||
SERVLET_RESOURCE_LOCATIONS.length);
|
||||
System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
|
||||
SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
|
||||
}
|
||||
|
||||
private static final String[] STATIC_INDEX_HTML_RESOURCES;
|
||||
static {
|
||||
STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
|
||||
for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
|
||||
STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
if (!registry.hasMappingForPattern("/**")) {
|
||||
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = 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()));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
return builder().build();
|
||||
}
|
||||
}
|
@ -1,2 +1 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
#server.port=8090
|
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -6,7 +6,7 @@
|
||||
<name>spring-boot-beanvalidation</name>
|
||||
<version>1.0.0</version>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>1.7</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.1.RELEASE</version>
|
||||
<version>1.5.12.RELEASE</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -48,16 +48,10 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<version>2.8.4</version>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
|
@ -4,7 +4,11 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +34,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurerAdapter() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.DateTimeUtils;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
@ -205,7 +205,7 @@ public class CustomInstantDeserializer<T extends Temporal>
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ public class OpenAPIDocumentationConfig {
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.api"))
|
||||
.build()
|
||||
.pathProvider(new BasePathAwareRelativePathProvider(servletContext, basePath))
|
||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)
|
||||
.apiInfo(apiInfo());
|
||||
|
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -48,7 +48,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -4,7 +4,10 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +33,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -6,7 +6,7 @@
|
||||
<name>springboot-delegate</name>
|
||||
<version>1.0.0</version>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>1.7</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.1.RELEASE</version>
|
||||
<version>1.5.12.RELEASE</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -48,16 +48,10 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<version>2.8.4</version>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
|
@ -4,7 +4,11 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +34,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurerAdapter() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.DateTimeUtils;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
@ -205,7 +205,7 @@ public class CustomInstantDeserializer<T extends Temporal>
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ public class OpenAPIDocumentationConfig {
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.api"))
|
||||
.build()
|
||||
.pathProvider(new BasePathAwareRelativePathProvider(servletContext, basePath))
|
||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)
|
||||
.apiInfo(apiInfo());
|
||||
|
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -48,7 +48,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -4,7 +4,10 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +33,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ This server was generated by the [OpenAPI Generator](https://openapi-generator.t
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
|
||||
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
Start your server as an simple java application
|
||||
|
||||
Change default port value in application.properties
|
@ -36,12 +36,20 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.14</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -4,7 +4,11 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +34,23 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebFluxConfigurer webConfigurer() {
|
||||
return new WebFluxConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
private static YAMLMapper yamlMapper = new YAMLMapper();
|
||||
|
||||
@Value("classpath:/openapi.yaml")
|
||||
private Resource openapi;
|
||||
|
||||
@Bean
|
||||
public String openapiContent() throws IOException {
|
||||
try(InputStream is = openapi.getInputStream()) {
|
||||
return StreamUtils.copyToString(is, Charset.defaultCharset());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi")
|
||||
@ResponseBody
|
||||
public String openapiYaml() throws IOException {
|
||||
return openapiContent();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.json", produces = "application/json")
|
||||
@ResponseBody
|
||||
public Object openapiJson() throws IOException {
|
||||
return yamlMapper.readValue(openapiContent(), Object.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> index() {
|
||||
return route(
|
||||
GET("/"),
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("swagger-ui/index.html?url=../openapi.json")).build()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.port=80
|
||||
spring.jackson.date-format=org.openapitools.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -48,7 +48,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -4,7 +4,10 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +33,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ The underlying library integrating OpenAPI to SpringBoot is [springfox](https://
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:80/
|
||||
|
||||
Change default port value in application.properties
|
@ -48,7 +48,6 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -4,7 +4,10 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
@ -30,4 +33,18 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -3,14 +3,17 @@ package org.openapitools.configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user