diff --git a/bin/ensure-up-to-date b/bin/ensure-up-to-date index ee3306929a33..74a65eb4d86f 100755 --- a/bin/ensure-up-to-date +++ b/bin/ensure-up-to-date @@ -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" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index fed7e6875c42..30ac8b9cb65b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -23,6 +23,7 @@ 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 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() { @@ -103,18 +103,19 @@ public SpringCodegen() { cliOptions.add(new CliOption(TITLE, "server title name or client service name")); cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code")); cliOptions.add(new CliOption(BASE_PACKAGE, "base package (invokerPackage) for generated code")); - cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.",interfaceOnly)); - cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern",delegatePattern)); - cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.",singleContentTypes)); - cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface",java8)); - cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers",async)); - cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)",reactive)); + cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly)); + cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern)); + cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.", singleContentTypes)); + cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface", java8)); + cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers", async)); + cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)", reactive)); cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)")); - cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames",useTags)); - 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(USE_OPTIONAL,"Use Optional container for optional parameters",useOptional)); + cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames", useTags)); + 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."); supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration."); @@ -145,9 +146,19 @@ public String getHelp() { @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 void processOpts() { 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 void processOpts() { 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 void processOpts() { (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 void processOpts() { } } 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 void processOpts() { (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 void processOpts() { 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 @@ private void removeHeadersFromAllParams(List<CodegenParameter> allParams) { @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 void setOpenapiDocketConfig(boolean openapiDocketConfig) { this.openapiDocketConfig = openapiDocketConfig; } + public void setApiFirst(boolean apiFirst) { + this.apiFirst = apiFirst; + } + @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/customInstantDeserializer.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/customInstantDeserializer.mustache index b7b8e251bdba..da7b57a61339 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/customInstantDeserializer.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/customInstantDeserializer.mustache @@ -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 { diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/homeController.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/homeController.mustache new file mode 100644 index 000000000000..f909a15b37df --- /dev/null +++ b/modules/openapi-generator/src/main/resources/JavaSpring/homeController.mustache @@ -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}} + + +} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/jacksonConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/jacksonConfiguration.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/jacksonConfiguration.mustache rename to modules/openapi-generator/src/main/resources/JavaSpring/jacksonConfiguration.mustache diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/README.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/README.mustache index 2f401bb621b0..b10f3dca28a6 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/README.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/README.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/application.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/application.mustache similarity index 84% rename from modules/openapi-generator/src/main/resources/JavaSpring/application.mustache rename to modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/application.mustache index 726647a19eb3..1193554dd225 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/application.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/application.mustache @@ -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 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/openapi2SpringBoot.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/openapi2SpringBoot.mustache index ccb880d8d0cb..1edc9208acb5 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/openapi2SpringBoot.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/openapi2SpringBoot.mustache @@ -4,10 +4,28 @@ 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}}"}) +@ComponentScan(basePackages = {"{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -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}} + }; + } + } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache index cf6f7158cfde..2d35c75cd1b7 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/jacksonConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/jacksonConfiguration.mustache deleted file mode 100644 index e96aa772c689..000000000000 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/jacksonConfiguration.mustache +++ /dev/null @@ -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; - } -} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/README.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/README.mustache index 464d6cdfa85e..d28df1b43b4b 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/README.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/README.mustache @@ -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 \ No newline at end of file +http://localhost:{{serverPort}}{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/ \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/application.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/application.mustache new file mode 100644 index 000000000000..67214287ed3d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/application.mustache @@ -0,0 +1,3 @@ +{{#useSpringfox}} +springfox.documentation.swagger.v2.path=/api-docs +{{/useSpringfox}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/openapiUiConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/openapiUiConfiguration.mustache index 2092ed66ffcd..a06212751454 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/openapiUiConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/openapiUiConfiguration.mustache @@ -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); } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/pom.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/pom.mustache index 960014f26945..f2f7ac73eb95 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/pom.mustache @@ -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> @@ -161,13 +207,13 @@ <version>${servlet-api-version}</version> </dependency> {{#useBeanValidation}} - <!-- Bean Validation API support --> - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${beanvalidation-version}</version> - <scope>provided</scope> - </dependency> + <!-- Bean Validation API support --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>${beanvalidation-version}</version> + <scope>provided</scope> + </dependency> {{/useBeanValidation}} </dependencies> <properties> @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/openapi.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/openapi.mustache new file mode 100644 index 000000000000..51ebafb0187d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/JavaSpring/openapi.mustache @@ -0,0 +1 @@ +{{{openapi-yaml}}} \ No newline at end of file diff --git a/samples/client/petstore/spring-stubs/pom.xml b/samples/client/petstore/spring-stubs/pom.xml index 0447482c4b41..df04e4752b15 100644 --- a/samples/client/petstore/spring-stubs/pom.xml +++ b/samples/client/petstore/spring-stubs/pom.xml @@ -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> diff --git a/samples/server/petstore/spring-mvc-j8-async/README.md b/samples/server/petstore/spring-mvc-j8-async/README.md index 1ce2fea319fb..4d5e52bd8f88 100644 --- a/samples/server/petstore/spring-mvc-j8-async/README.md +++ b/samples/server/petstore/spring-mvc-j8-async/README.md @@ -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 \ No newline at end of file +http://localhost:8002/v2/ \ No newline at end of file diff --git a/samples/server/petstore/spring-mvc-j8-async/pom.xml b/samples/server/petstore/spring-mvc-j8-async/pom.xml index a40efa75207b..150c533f5a5a 100644 --- a/samples/server/petstore/spring-mvc-j8-async/pom.xml +++ b/samples/server/petstore/spring-mvc-j8-async/pom.xml @@ -94,7 +94,6 @@ <artifactId>spring-web</artifactId> <version>${spring-version}</version> </dependency> - <!--SpringFox dependencies--> <dependency> <groupId>io.springfox</groupId> @@ -112,7 +111,6 @@ <artifactId>springfox-swagger-ui</artifactId> <version>${springfox-version}</version> </dependency> - <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> @@ -130,13 +128,13 @@ <artifactId>servlet-api</artifactId> <version>${servlet-api-version}</version> </dependency> - <!-- Bean Validation API support --> - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${beanvalidation-version}</version> - <scope>provided</scope> - </dependency> + <!-- Bean Validation API support --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>${beanvalidation-version}</version> + <scope>provided</scope> + </dependency> </dependencies> <properties> <java.version>1.8</java.version> @@ -146,9 +144,9 @@ <slf4j-version>1.7.21</slf4j-version> <junit-version>4.12</junit-version> <servlet-api-version>2.5</servlet-api-version> - <springfox-version>2.7.0</springfox-version> - <jackson-version>2.8.9</jackson-version> - <jackson-threetenbp-version>2.6.4</jackson-threetenbp-version> + <springfox-version>2.8.0</springfox-version> + <jackson-version>2.9.5</jackson-version> + <jackson-threetenbp-version>2.8.4</jackson-threetenbp-version> <beanvalidation-version>1.1.0.Final</beanvalidation-version> <spring-version>4.3.9.RELEASE</spring-version> </properties> diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/homeController.mustache b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/HomeController.java similarity index 60% rename from modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/homeController.mustache rename to samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/HomeController.java index 91a07d5efb77..25727830541b 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/homeController.mustache +++ b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/HomeController.java @@ -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"; } + + } diff --git a/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java index 2840efe3f193..e04a1577033a 100644 --- a/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java +++ b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java @@ -8,6 +8,7 @@ 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 @@ @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 void addResourceHandlers(ResourceHandlerRegistry registry) { } } + /*@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); } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/application.properties b/samples/server/petstore/spring-mvc-j8-async/src/main/resources/application.properties similarity index 73% rename from modules/openapi-generator/src/main/resources/JavaSpring/application.properties rename to samples/server/petstore/spring-mvc-j8-async/src/main/resources/application.properties index 8d3a7a8292be..99ebf4d7c55e 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/application.properties +++ b/samples/server/petstore/spring-mvc-j8-async/src/main/resources/application.properties @@ -1,2 +1 @@ springfox.documentation.swagger.v2.path=/api-docs -#server.port=8090 diff --git a/samples/server/petstore/spring-mvc-j8-localdatetime/README.md b/samples/server/petstore/spring-mvc-j8-localdatetime/README.md index 1ce2fea319fb..4d5e52bd8f88 100644 --- a/samples/server/petstore/spring-mvc-j8-localdatetime/README.md +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/README.md @@ -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 \ No newline at end of file +http://localhost:8002/v2/ \ No newline at end of file diff --git a/samples/server/petstore/spring-mvc-j8-localdatetime/pom.xml b/samples/server/petstore/spring-mvc-j8-localdatetime/pom.xml index 60f6f0b1df58..fe2492e60ae0 100644 --- a/samples/server/petstore/spring-mvc-j8-localdatetime/pom.xml +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/pom.xml @@ -94,7 +94,6 @@ <artifactId>spring-web</artifactId> <version>${spring-version}</version> </dependency> - <!--SpringFox dependencies--> <dependency> <groupId>io.springfox</groupId> @@ -112,7 +111,6 @@ <artifactId>springfox-swagger-ui</artifactId> <version>${springfox-version}</version> </dependency> - <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> @@ -130,13 +128,13 @@ <artifactId>servlet-api</artifactId> <version>${servlet-api-version}</version> </dependency> - <!-- Bean Validation API support --> - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${beanvalidation-version}</version> - <scope>provided</scope> - </dependency> + <!-- Bean Validation API support --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>${beanvalidation-version}</version> + <scope>provided</scope> + </dependency> </dependencies> <properties> <java.version>1.8</java.version> @@ -146,9 +144,9 @@ <slf4j-version>1.7.21</slf4j-version> <junit-version>4.12</junit-version> <servlet-api-version>2.5</servlet-api-version> - <springfox-version>2.7.0</springfox-version> - <jackson-version>2.8.9</jackson-version> - <jackson-threetenbp-version>2.6.4</jackson-threetenbp-version> + <springfox-version>2.8.0</springfox-version> + <jackson-version>2.9.5</jackson-version> + <jackson-threetenbp-version>2.8.4</jackson-threetenbp-version> <beanvalidation-version>1.1.0.Final</beanvalidation-version> <spring-version>4.3.9.RELEASE</spring-version> </properties> diff --git a/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 000000000000..25727830541b --- /dev/null +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/HomeController.java @@ -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"; + } + + +} diff --git a/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java index 2840efe3f193..e04a1577033a 100644 --- a/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java @@ -8,6 +8,7 @@ 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 @@ @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 void addResourceHandlers(ResourceHandlerRegistry registry) { } } + /*@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); } diff --git a/samples/server/petstore/spring-mvc/src/main/resources/openapi.properties b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/resources/application.properties similarity index 73% rename from samples/server/petstore/spring-mvc/src/main/resources/openapi.properties rename to samples/server/petstore/spring-mvc-j8-localdatetime/src/main/resources/application.properties index 8d3a7a8292be..99ebf4d7c55e 100644 --- a/samples/server/petstore/spring-mvc/src/main/resources/openapi.properties +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/resources/application.properties @@ -1,2 +1 @@ springfox.documentation.swagger.v2.path=/api-docs -#server.port=8090 diff --git a/samples/server/petstore/spring-mvc/README.md b/samples/server/petstore/spring-mvc/README.md index 1ce2fea319fb..4d5e52bd8f88 100644 --- a/samples/server/petstore/spring-mvc/README.md +++ b/samples/server/petstore/spring-mvc/README.md @@ -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 \ No newline at end of file +http://localhost:8002/v2/ \ No newline at end of file diff --git a/samples/server/petstore/spring-mvc/pom.xml b/samples/server/petstore/spring-mvc/pom.xml index b1d3999145f9..80f5025a609c 100644 --- a/samples/server/petstore/spring-mvc/pom.xml +++ b/samples/server/petstore/spring-mvc/pom.xml @@ -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> @@ -136,25 +128,25 @@ <artifactId>servlet-api</artifactId> <version>${servlet-api-version}</version> </dependency> - <!-- Bean Validation API support --> - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${beanvalidation-version}</version> - <scope>provided</scope> - </dependency> + <!-- Bean Validation API support --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>${beanvalidation-version}</version> + <scope>provided</scope> + </dependency> </dependencies> <properties> - <java.version>1.8</java.version> + <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> diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java index 0a2b8e4eacf7..8f936b311447 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java +++ b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java @@ -5,12 +5,12 @@ 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 T deserialize(JsonParser parser, DeserializationContext context) throws I 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 { diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 000000000000..25727830541b --- /dev/null +++ b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/HomeController.java @@ -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"; + } + + +} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java index 68e2e36f3704..2aba2deb8eab 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java +++ b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java @@ -40,9 +40,6 @@ public Docket customImplementation(ServletContext servletContext, @Value("${open .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()); diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java index d67b926b3470..0707ad35d41a 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java +++ b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java @@ -9,6 +9,7 @@ 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 @@ @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 void addResourceHandlers(ResourceHandlerRegistry registry) { } } + /*@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); } diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerDocumentationConfig.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerDocumentationConfig.java deleted file mode 100644 index 99f3575e1356..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerDocumentationConfig.java +++ /dev/null @@ -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()); - } - -} diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerUiConfiguration.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerUiConfiguration.java deleted file mode 100644 index 380983cce8e9..000000000000 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/configuration/SwaggerUiConfiguration.java +++ /dev/null @@ -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(); - } -} diff --git a/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties b/samples/server/petstore/spring-mvc/src/main/resources/application.properties similarity index 73% rename from samples/server/petstore/spring-mvc/src/main/resources/swagger.properties rename to samples/server/petstore/spring-mvc/src/main/resources/application.properties index 8d3a7a8292be..99ebf4d7c55e 100644 --- a/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties +++ b/samples/server/petstore/spring-mvc/src/main/resources/application.properties @@ -1,2 +1 @@ springfox.documentation.swagger.v2.path=/api-docs -#server.port=8090 diff --git a/samples/server/petstore/springboot-beanvalidation/README.md b/samples/server/petstore/springboot-beanvalidation/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot-beanvalidation/README.md +++ b/samples/server/petstore/springboot-beanvalidation/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-beanvalidation/pom.xml b/samples/server/petstore/springboot-beanvalidation/pom.xml index 2a1f222289d9..6cdccc35449b 100644 --- a/samples/server/petstore/springboot-beanvalidation/pom.xml +++ b/samples/server/petstore/springboot-beanvalidation/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..6d45fdaaf91b 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,14 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +34,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurerAdapter() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java index 0a2b8e4eacf7..8f936b311447 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java @@ -5,12 +5,12 @@ 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 T deserialize(JsonParser parser, DeserializationContext context) throws I 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 { diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + } diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java index 3307fc00b59d..a18a521a0bfe 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java @@ -40,9 +40,6 @@ public Docket customImplementation(ServletContext servletContext, @Value("${open .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()); diff --git a/samples/server/petstore/springboot-delegate-j8/README.md b/samples/server/petstore/springboot-delegate-j8/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot-delegate-j8/README.md +++ b/samples/server/petstore/springboot-delegate-j8/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-delegate-j8/pom.xml b/samples/server/petstore/springboot-delegate-j8/pom.xml index e6f7189f1101..89dde1e2e47f 100644 --- a/samples/server/petstore/springboot-delegate-j8/pom.xml +++ b/samples/server/petstore/springboot-delegate-j8/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..cb4725930798 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,13 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +33,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + } diff --git a/samples/server/petstore/springboot-delegate/README.md b/samples/server/petstore/springboot-delegate/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot-delegate/README.md +++ b/samples/server/petstore/springboot-delegate/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-delegate/pom.xml b/samples/server/petstore/springboot-delegate/pom.xml index 1d43e89e85f9..0922249a473f 100644 --- a/samples/server/petstore/springboot-delegate/pom.xml +++ b/samples/server/petstore/springboot-delegate/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..6d45fdaaf91b 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,14 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +34,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurerAdapter() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java index 0a2b8e4eacf7..8f936b311447 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/CustomInstantDeserializer.java @@ -5,12 +5,12 @@ 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 T deserialize(JsonParser parser, DeserializationContext context) throws I 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 { diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java index 3307fc00b59d..a18a521a0bfe 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java @@ -40,9 +40,6 @@ public Docket customImplementation(ServletContext servletContext, @Value("${open .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()); diff --git a/samples/server/petstore/springboot-implicitHeaders/README.md b/samples/server/petstore/springboot-implicitHeaders/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot-implicitHeaders/README.md +++ b/samples/server/petstore/springboot-implicitHeaders/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-implicitHeaders/pom.xml b/samples/server/petstore/springboot-implicitHeaders/pom.xml index fb0b15917f18..5495d34798b4 100644 --- a/samples/server/petstore/springboot-implicitHeaders/pom.xml +++ b/samples/server/petstore/springboot-implicitHeaders/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..cb4725930798 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,13 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +33,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + } diff --git a/samples/server/petstore/springboot-reactive/README.md b/samples/server/petstore/springboot-reactive/README.md index a12a59c79ed0..c24c6206ab1a 100644 --- a/samples/server/petstore/springboot-reactive/README.md +++ b/samples/server/petstore/springboot-reactive/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-reactive/pom.xml b/samples/server/petstore/springboot-reactive/pom.xml index e2489f1db63a..4f3818a86cfd 100644 --- a/samples/server/petstore/springboot-reactive/pom.xml +++ b/samples/server/petstore/springboot-reactive/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..f38e8a28ffa4 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,14 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +34,23 @@ public int getExitCode() { } } + + @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/"); + } + }; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 000000000000..b1e5bfc21ee5 --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/configuration/HomeController.java @@ -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() + ); + } + + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/resources/application.properties b/samples/server/petstore/springboot-reactive/src/main/resources/application.properties index 13b0dc6ab966..6512a5b02e42 100644 --- a/samples/server/petstore/springboot-reactive/src/main/resources/application.properties +++ b/samples/server/petstore/springboot-reactive/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml new file mode 100644 index 000000000000..8bf8a08e0b6b --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml @@ -0,0 +1,1624 @@ +openapi: 3.0.1 +info: + 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: + name: Apache-2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + title: OpenAPI Petstore + version: 1.0.0 +servers: +- url: http://petstore.swagger.io:80/v2 +tags: +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user +paths: + /pet: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + responses: + 405: + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: pet + put: + operationId: updatePet + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + responses: + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Pet not found + 405: + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: pet + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - description: Status values that need to be considered for filter + explode: false + in: query + name: status + required: true + schema: + items: + default: available + enum: + - available + - pending + - sold + type: string + type: array + style: form + responses: + 200: + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + 400: + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by status + tags: + - pet + x-accepts: application/json + x-tags: + - tag: pet + /pet/findByTags: + get: + deprecated: true + description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - description: Tags to filter by + explode: false + in: query + name: tags + required: true + schema: + items: + type: string + type: array + style: form + responses: + 200: + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + 400: + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + x-accepts: application/json + x-tags: + - tag: pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + 400: + content: {} + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet + tags: + - pet + x-accepts: application/json + x-tags: + - tag: pet + get: + description: Returns a single pet + operationId: getPetById + parameters: + - description: ID of pet to return + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + 200: + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + x-accepts: application/json + x-tags: + - tag: pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + 405: + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Updates a pet in the store with form data + tags: + - pet + x-contentType: application/x-www-form-urlencoded + x-accepts: application/json + x-tags: + - tag: pet + /pet/{petId}/uploadImage: + post: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + responses: + 200: + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an image + tags: + - pet + x-contentType: multipart/form-data + x-accepts: application/json + x-tags: + - tag: pet + /store/inventory: + get: + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + 200: + content: + application/json: + schema: + additionalProperties: + format: int32 + type: integer + type: object + description: successful operation + security: + - api_key: [] + summary: Returns pet inventories by status + tags: + - store + x-accepts: application/json + x-tags: + - tag: store + /store/order: + post: + operationId: placeOrder + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + responses: + 200: + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + 400: + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-contentType: '*/*' + x-accepts: application/json + x-tags: + - tag: store + /store/order/{order_id}: + delete: + description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - description: ID of the order that needs to be deleted + in: path + name: order_id + required: true + schema: + type: string + responses: + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Order not found + summary: Delete purchase order by ID + tags: + - store + x-accepts: application/json + x-tags: + - tag: store + get: + description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: order_id + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + 200: + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Order not found + summary: Find purchase order by ID + tags: + - store + x-accepts: application/json + x-tags: + - tag: store + /user: + post: + description: This can only be done by the logged in user. + operationId: createUser + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-contentType: '*/*' + x-accepts: application/json + x-tags: + - tag: user + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-contentType: '*/*' + x-accepts: application/json + x-tags: + - tag: user + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-contentType: '*/*' + x-accepts: application/json + x-tags: + - tag: user + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + 200: + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + 400: + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + x-accepts: application/json + x-tags: + - tag: user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + summary: Logs out current logged in user session + tags: + - user + x-accepts: application/json + x-tags: + - tag: user + /user/{username}: + delete: + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - description: The name that needs to be deleted + in: path + name: username + required: true + schema: + type: string + responses: + 400: + content: {} + description: Invalid username supplied + 404: + content: {} + description: User not found + summary: Delete user + tags: + - user + x-accepts: application/json + x-tags: + - tag: user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + 200: + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + 400: + content: {} + description: Invalid username supplied + 404: + content: {} + description: User not found + summary: Get user by user name + tags: + - user + x-accepts: application/json + x-tags: + - tag: user + put: + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - description: name that need to be deleted + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + 400: + content: {} + description: Invalid user supplied + 404: + content: {} + description: User not found + summary: Updated user + tags: + - user + x-contentType: '*/*' + x-accepts: application/json + x-tags: + - tag: user + /fake_classname_test: + patch: + description: To test class name in snake case + operationId: testClassname + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: client model + required: true + responses: + 200: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: successful operation + security: + - api_key_query: [] + summary: To test class name in snake case + tags: + - fake_classname_tags 123#$%^ + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: fake_classname_tags 123#$%^ + /fake: + get: + description: To test enum parameters + operationId: testEnumParameters + parameters: + - description: Header parameter enum test (string array) + explode: false + in: header + name: enum_header_string_array + schema: + items: + default: $ + enum: + - '>' + - $ + type: string + type: array + style: simple + - description: Header parameter enum test (string) + in: header + name: enum_header_string + schema: + default: -efg + enum: + - _abc + - -efg + - (xyz) + type: string + - description: Query parameter enum test (string array) + explode: false + in: query + name: enum_query_string_array + schema: + items: + default: $ + enum: + - '>' + - $ + type: string + type: array + style: form + - description: Query parameter enum test (string) + in: query + name: enum_query_string + schema: + default: -efg + enum: + - _abc + - -efg + - (xyz) + type: string + - description: Query parameter enum test (double) + in: query + name: enum_query_integer + schema: + enum: + - 1 + - -2 + format: int32 + type: integer + - description: Query parameter enum test (double) + in: query + name: enum_query_double + schema: + enum: + - 1.1 + - -1.2 + format: double + type: number + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + enum_form_string_array: + description: Form parameter enum test (string array) + items: + default: $ + enum: + - '>' + - $ + type: string + type: array + enum_form_string: + default: -efg + description: Form parameter enum test (string) + enum: + - _abc + - -efg + - (xyz) + type: string + responses: + 400: + content: {} + description: Invalid request + 404: + content: {} + description: Not found + summary: To test enum parameters + tags: + - fake + x-contentType: application/x-www-form-urlencoded + x-accepts: application/json + x-tags: + - tag: fake + patch: + description: To test "client" model + operationId: testClientModel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: client model + required: true + responses: + 200: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: successful operation + summary: To test "client" model + tags: + - fake + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: fake + post: + description: | + Fake endpoint for testing various parameters + 假端點 + 偽のエンドポイント + 가짜 엔드 포인트 + operationId: testEndpointParameters + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + integer: + description: None + maximum: 100 + minimum: 10 + type: integer + int32: + description: None + format: int32 + maximum: 200 + minimum: 20 + type: integer + int64: + description: None + format: int64 + type: integer + number: + description: None + maximum: 543.2 + minimum: 32.1 + type: number + float: + description: None + format: float + maximum: 987.6 + type: number + double: + description: None + format: double + maximum: 123.4 + minimum: 67.8 + type: number + string: + description: None + pattern: /[a-z]/i + type: string + pattern_without_delimiter: + description: None + pattern: ^[A-Z].* + type: string + byte: + description: None + format: byte + type: string + binary: + description: None + format: binary + type: string + date: + description: None + format: date + type: string + dateTime: + description: None + format: date-time + type: string + password: + description: None + format: password + maxLength: 64 + minLength: 10 + type: string + callback: + description: None + type: string + required: + - byte + - double + - number + - pattern_without_delimiter + required: true + responses: + 400: + content: {} + description: Invalid username supplied + 404: + content: {} + description: User not found + security: + - http_basic_test: [] + summary: | + Fake endpoint for testing various parameters + 假端點 + 偽のエンドポイント + 가짜 엔드 포인트 + tags: + - fake + x-contentType: application/x-www-form-urlencoded + x-accepts: application/json + x-tags: + - tag: fake + /fake/outer/number: + post: + description: Test serialization of outer number types + operationId: fakeOuterNumberSerialize + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterNumber' + description: Input number as post body + required: false + responses: + 200: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterNumber' + description: Output number + tags: + - fake + x-contentType: '*/*' + x-accepts: '*/*' + x-tags: + - tag: fake + /fake/outer/string: + post: + description: Test serialization of outer string types + operationId: fakeOuterStringSerialize + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterString' + description: Input string as post body + required: false + responses: + 200: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterString' + description: Output string + tags: + - fake + x-contentType: '*/*' + x-accepts: '*/*' + x-tags: + - tag: fake + /fake/outer/boolean: + post: + description: Test serialization of outer boolean types + operationId: fakeOuterBooleanSerialize + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterBoolean' + description: Input boolean as post body + required: false + responses: + 200: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterBoolean' + description: Output boolean + tags: + - fake + x-contentType: '*/*' + x-accepts: '*/*' + x-tags: + - tag: fake + /fake/outer/composite: + post: + description: Test serialization of object with outer number type + operationId: fakeOuterCompositeSerialize + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterComposite' + description: Input composite as post body + required: false + responses: + 200: + content: + '*/*': + schema: + $ref: '#/components/schemas/OuterComposite' + description: Output composite + tags: + - fake + x-contentType: '*/*' + x-accepts: '*/*' + x-tags: + - tag: fake + /fake/jsonFormData: + get: + operationId: testJsonFormData + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + param: + description: field1 + type: string + param2: + description: field2 + type: string + required: + - param + - param2 + required: true + responses: + 200: + content: {} + description: successful operation + summary: test json serialization of form data + tags: + - fake + x-contentType: application/x-www-form-urlencoded + x-accepts: application/json + x-tags: + - tag: fake + /fake/inline-additionalProperties: + post: + operationId: testInlineAdditionalProperties + requestBody: + content: + application/json: + schema: + additionalProperties: + type: string + type: object + description: request body + required: true + responses: + 200: + content: {} + description: successful operation + summary: test inline additionalProperties + tags: + - fake + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: fake + /fake/body-with-query-params: + put: + operationId: testBodyWithQueryParams + parameters: + - in: query + name: query + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + required: true + responses: + 200: + content: {} + description: Success + tags: + - fake + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: fake + /another-fake/dummy: + patch: + description: To test special tags + operationId: test_special_tags + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: client model + required: true + responses: + 200: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: successful operation + summary: To test special tags + tags: + - $another-fake? + x-contentType: application/json + x-accepts: application/json + x-tags: + - tag: $another-fake? +components: + schemas: + Category: + example: + name: name + id: 6 + properties: + id: + format: int64 + type: integer + name: + type: string + type: object + xml: + name: Category + User: + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username + properties: + id: + format: int64 + type: integer + x-is-unique: true + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + description: User Status + format: int32 + type: integer + type: object + xml: + name: User + OuterNumber: + type: number + ArrayOfNumberOnly: + properties: + ArrayNumber: + items: + type: number + type: array + type: object + Capitalization: + properties: + smallCamel: + type: string + CapitalCamel: + type: string + small_Snake: + type: string + Capital_Snake: + type: string + SCA_ETH_Flow_Points: + type: string + ATT_NAME: + description: | + Name of the pet + type: string + type: object + MixedPropertiesAndAdditionalPropertiesClass: + properties: + uuid: + format: uuid + type: string + dateTime: + format: date-time + type: string + map: + additionalProperties: + $ref: '#/components/schemas/Animal' + type: object + type: object + ApiResponse: + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + type: object + Name: + description: Model for testing model name same as property name + properties: + name: + format: int32 + type: integer + snake_case: + format: int32 + readOnly: true + type: integer + property: + type: string + 123Number: + readOnly: true + type: integer + required: + - name + type: object + xml: + name: Name + EnumClass: + default: -efg + enum: + - _abc + - -efg + - (xyz) + type: string + List: + example: + 123-list: 123-list + properties: + 123-list: + type: string + type: object + NumberOnly: + properties: + JustNumber: + type: number + type: object + 200_response: + description: Model for testing model name starting with number + properties: + name: + format: int32 + type: integer + class: + type: string + type: object + xml: + name: Name + Client: + example: + client: client + properties: + client: + type: string + type: object + Dog: + allOf: + - $ref: '#/components/schemas/Animal' + - properties: + breed: + type: string + type: object + Enum_Test: + properties: + enum_string: + enum: + - UPPER + - lower + - "" + type: string + enum_string_required: + enum: + - UPPER + - lower + - "" + type: string + enum_integer: + enum: + - 1 + - -1 + format: int32 + type: integer + enum_number: + enum: + - 1.1 + - -1.2 + format: double + type: number + outerEnum: + $ref: '#/components/schemas/OuterEnum' + required: + - enum_string_required + type: object + Order: + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed + properties: + id: + format: int64 + type: integer + petId: + format: int64 + type: integer + quantity: + format: int32 + type: integer + shipDate: + format: date-time + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + type: string + complete: + default: false + type: boolean + type: object + xml: + name: Order + AdditionalPropertiesClass: + properties: + map_property: + additionalProperties: + type: string + type: object + map_of_map_property: + additionalProperties: + additionalProperties: + type: string + type: object + type: object + type: object + $special[model.name]: + properties: + $special[property.name]: + format: int64 + type: integer + type: object + xml: + name: $special[model.name] + Return: + description: Model for testing reserved words + properties: + return: + format: int32 + type: integer + type: object + xml: + name: Return + ReadOnlyFirst: + properties: + bar: + readOnly: true + type: string + baz: + type: string + type: object + ArrayOfArrayOfNumberOnly: + properties: + ArrayArrayNumber: + items: + items: + type: number + type: array + type: array + type: object + OuterEnum: + enum: + - placed + - approved + - delivered + type: string + ArrayTest: + properties: + array_of_string: + items: + type: string + type: array + array_array_of_integer: + items: + items: + format: int64 + type: integer + type: array + type: array + array_array_of_model: + items: + items: + $ref: '#/components/schemas/ReadOnlyFirst' + type: array + type: array + type: object + OuterComposite: + example: {} + properties: + my_number: + $ref: '#/components/schemas/OuterNumber' + my_string: + $ref: '#/components/schemas/OuterString' + my_boolean: + $ref: '#/components/schemas/OuterBoolean' + type: object + format_test: + properties: + integer: + maximum: 1E+2 + minimum: 1E+1 + type: integer + int32: + format: int32 + maximum: 2E+2 + minimum: 2E+1 + type: integer + int64: + format: int64 + type: integer + number: + maximum: 543.2 + minimum: 32.1 + type: number + float: + format: float + maximum: 987.6 + minimum: 54.3 + type: number + double: + format: double + maximum: 123.4 + minimum: 67.8 + type: number + string: + pattern: /[a-z]/i + type: string + byte: + format: byte + pattern: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ + type: string + binary: + format: binary + type: string + date: + format: date + type: string + dateTime: + format: date-time + type: string + uuid: + format: uuid + type: string + password: + format: password + maxLength: 64 + minLength: 10 + type: string + required: + - byte + - date + - number + - password + type: object + EnumArrays: + properties: + just_symbol: + enum: + - '>=' + - $ + type: string + array_enum: + items: + enum: + - fish + - crab + type: string + type: array + type: object + OuterString: + type: string + ClassModel: + description: Model for testing model with "_class" property + properties: + _class: + type: string + type: object + OuterBoolean: + type: boolean + x-codegen-body-parameter-name: boolean_post_body + Animal: + discriminator: + propertyName: className + properties: + className: + type: string + color: + default: red + type: string + required: + - className + type: object + Cat: + allOf: + - $ref: '#/components/schemas/Animal' + - properties: + declawed: + type: boolean + type: object + MapTest: + properties: + map_map_of_string: + additionalProperties: + additionalProperties: + type: string + type: object + type: object + map_of_enum_string: + additionalProperties: + enum: + - UPPER + - lower + type: string + type: object + type: object + Tag: + example: + name: name + id: 1 + properties: + id: + format: int64 + type: integer + name: + type: string + type: object + xml: + name: Tag + AnimalFarm: + items: + $ref: '#/components/schemas/Animal' + type: array + Pet: + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available + properties: + id: + format: int64 + type: integer + x-is-unique: true + category: + $ref: '#/components/schemas/Category' + name: + example: doggie + type: string + photoUrls: + items: + type: string + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + type: array + xml: + name: tag + wrapped: true + status: + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + type: object + xml: + name: Pet + hasOnlyReadOnly: + properties: + bar: + readOnly: true + type: string + foo: + readOnly: true + type: string + type: object + securitySchemes: + petstore_auth: + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + type: oauth2 + http_basic_test: + scheme: basic + type: http + api_key: + in: header + name: api_key + type: apiKey + api_key_query: + in: query + name: api_key_query + type: apiKey diff --git a/samples/server/petstore/springboot-useoptional/README.md b/samples/server/petstore/springboot-useoptional/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot-useoptional/README.md +++ b/samples/server/petstore/springboot-useoptional/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot-useoptional/pom.xml b/samples/server/petstore/springboot-useoptional/pom.xml index c4cec44aa9b2..20429c0fc5fc 100644 --- a/samples/server/petstore/springboot-useoptional/pom.xml +++ b/samples/server/petstore/springboot-useoptional/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..cb4725930798 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,13 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +33,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + } diff --git a/samples/server/petstore/springboot/README.md b/samples/server/petstore/springboot/README.md index f7a85c933038..44429ae92381 100644 --- a/samples/server/petstore/springboot/README.md +++ b/samples/server/petstore/springboot/README.md @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/springboot/pom.xml b/samples/server/petstore/springboot/pom.xml index 59d0c0b48968..477821557afc 100644 --- a/samples/server/petstore/springboot/pom.xml +++ b/samples/server/petstore/springboot/pom.xml @@ -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> diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/OpenAPI2SpringBoot.java index 96efbff799eb..cb4725930798 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/OpenAPI2SpringBoot.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -4,10 +4,13 @@ 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"}) +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) public class OpenAPI2SpringBoot implements CommandLineRunner { @Override @@ -30,4 +33,18 @@ public int getExitCode() { } } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + }; + } + } diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiException.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiException.java deleted file mode 100644 index fdbaeee3a29e..000000000000 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiOriginFilter.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiOriginFilter.java deleted file mode 100644 index 32424c32c4cc..000000000000 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiOriginFilter.java +++ /dev/null @@ -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 { - } -} diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiResponseMessage.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiResponseMessage.java deleted file mode 100644 index c85c5b51afdf..000000000000 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiResponseMessage.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/NotFoundException.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/NotFoundException.java deleted file mode 100644 index 526df6c1c197..000000000000 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/NotFoundException.java +++ /dev/null @@ -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; - } -} diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/configuration/HomeController.java index c431c81a6abd..25727830541b 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/configuration/HomeController.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/configuration/HomeController.java @@ -3,14 +3,17 @@ 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"; } + + }