forked from loafle/openapi-generator-original
Implement Source DocumentationProvider, spring-mvc
decommission (#11531)
* - Upgrade swagger-ui to 4.4.1 - Bring homeController.mustache up-to-date - Main class is now OpenApiGeneratorApplication - Introduce SpringBootTest.mustache - Remove option swaggerDocketConfig/openapiDocketConfig in favor of documentationProvider. * Generate Samples * Restore generator-online classes Fix spring-mvc builds * Generate Samples * Do not generate SpringFoxConfiguration.java when reactive ist set. * Fix generation of SpringFoxConfiguration * Generate Documentation * Reactive support: add dependency management for springdoc-openapi-webflux-ui * Generate Samples * Change SpringBootApplication to OpenApiGeneratorApplication * Generate Samples * Implement SwaggerUIFeatures in SpringCodegen * Generate Samples * Add useSwaggerUI: true to some test configs * Generate Samples * Update Documentation * Update Documentation * Update README.mustache * Generate Samples * useSwaggerUI is true by default * Generate Samples * Update Documentation * Add deprecation warnings to cli opts; Log a deprecation warning * Update Documentation * Generate Samples * Remove spring-mvc library * Remove spring-mvc from project and CI configs * Check whether the selected documentation provider requires us to boostrap swagger-ui. * Generate Samples * Generate samples * Generate samples * Generate samples
This commit is contained in:
parent
b01bcfecde
commit
0ed147e7a4
18
.github/.test/samples.json
vendored
18
.github/.test/samples.json
vendored
@ -920,24 +920,6 @@
|
||||
"Server: Spring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"input": "spring-mvc-petstore-j8-async-server.sh",
|
||||
"matches": [
|
||||
"Server: Spring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"input": "spring-mvc-petstore-j8-localdatetime.sh",
|
||||
"matches": [
|
||||
"Server: Spring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"input": "spring-mvc-petstore-server.sh",
|
||||
"matches": [
|
||||
"Server: Spring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"input": "spring-stubs.sh",
|
||||
"matches": [
|
||||
|
4
.github/workflows/samples-spring.yaml
vendored
4
.github/workflows/samples-spring.yaml
vendored
@ -26,10 +26,6 @@ jobs:
|
||||
- samples/openapi3/client/petstore/spring-stubs
|
||||
- samples/openapi3/client/petstore/spring-stubs-skip-default-interface
|
||||
# servers
|
||||
- samples/server/petstore/spring-mvc
|
||||
- samples/server/petstore/spring-mvc-default-value
|
||||
- samples/server/petstore/spring-mvc-j8-async
|
||||
- samples/server/petstore/spring-mvc-j8-localdatetime
|
||||
- samples/server/petstore/springboot
|
||||
- samples/openapi3/server/petstore/springboot
|
||||
- samples/server/petstore/springboot-beanvalidation
|
||||
|
@ -5,6 +5,7 @@ inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-e
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
useSwaggerUI: false
|
||||
java8: true
|
||||
useBeanValidation: true
|
||||
artifactId: spring-boot-beanvalidation
|
||||
|
10
bin/configs/spring-boot-source.yaml
Normal file
10
bin/configs/spring-boot-source.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/openapi3/server/petstore/springboot-source
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
groupId: org.openapitools.openapi3
|
||||
documentationProvider: source
|
||||
artifactId: springboot
|
||||
snapshotVersion: "true"
|
||||
hideGenerationTimestamp: "true"
|
@ -5,6 +5,7 @@ templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
groupId: org.openapitools.openapi3
|
||||
documentationProvider: springdoc
|
||||
useSwaggerUI: false
|
||||
artifactId: spring-boot-springdoc
|
||||
snapshotVersion: "true"
|
||||
hideGenerationTimestamp: "true"
|
||||
|
@ -1,8 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc-default-value
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_8535.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
hideGenerationTimestamp: "true"
|
||||
artifactId: spring-mvc-default-value
|
@ -1,12 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc-j8-async
|
||||
library: spring-mvc
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
async: "true"
|
||||
java8: true
|
||||
artifactId: spring-mvc-server-j8-async
|
||||
hideGenerationTimestamp: "true"
|
||||
serverPort: "8002"
|
@ -1,12 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc-j8-localdatetime
|
||||
library: spring-mvc
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
booleanGetterPrefix: get
|
||||
artifactId: spring-mvc-j8-localdatetime
|
||||
hideGenerationTimestamp: "true"
|
||||
serverPort: "8002"
|
||||
dateLibrary: java8-localdatetime
|
@ -1,11 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc-no-nullable
|
||||
library: spring-mvc
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
artifactId: spring-mvc-server-no-nullable
|
||||
openApiNullable: "false"
|
||||
serverPort: "8002"
|
||||
hideGenerationTimestamp: "true"
|
@ -1,9 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc-spring-pageable
|
||||
library: spring-mvc
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
artifactId: spring-mvc-spring-pageable
|
||||
hideGenerationTimestamp: 'true'
|
@ -1,14 +0,0 @@
|
||||
generatorName: spring
|
||||
outputDir: samples/server/petstore/spring-mvc
|
||||
library: spring-mvc
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
|
||||
additionalProperties:
|
||||
documentationProvider: springfox
|
||||
java8: true
|
||||
booleanGetterPrefix: get
|
||||
artifactId: spring-mvc-server
|
||||
hideGenerationTimestamp: "true"
|
||||
serverPort: "8002"
|
||||
additionalModelTypeAnnotations: '@com.fasterxml.jackson.annotation.JsonFilter(value = "filter-name");@com.fasterxml.jackson.annotation.JsonIgnoreProperties(value = "id")'
|
||||
additionalEnumTypeAnnotations: '@com.fasterxml.jackson.annotation.JsonFormat'
|
@ -49,7 +49,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false|
|
||||
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|
||||
|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true|
|
||||
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd><dt>**springfox**</dt><dd>Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x.</dd><dt>**springdoc**</dt><dd>Generate an OpenAPI 3 specification using SpringDoc.</dd></dl>|springdoc|
|
||||
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd><dt>**springfox**</dt><dd>Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.</dd><dt>**springdoc**</dt><dd>Generate an OpenAPI 3 specification using SpringDoc.</dd></dl>|springdoc|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
|
||||
|fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false|
|
||||
@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||
|invokerPackage|root package for generated code| |org.openapitools.api|
|
||||
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application using the SpringFox integration.</dd><dt>**spring-mvc**</dt><dd>Spring-MVC Server application using the SpringFox integration.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd></dl>|spring-boot|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd></dl>|spring-boot|
|
||||
|licenseName|The name of the license| |Unlicense|
|
||||
|licenseUrl|The URL of the license| |http://unlicense.org|
|
||||
|modelPackage|package for generated models| |org.openapitools.model|
|
||||
@ -84,13 +84,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|swaggerDocketConfig|Generate Spring OpenAPI Docket configuration class.| |false|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|title|server title name or client service name| |OpenAPI Spring|
|
||||
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|
||||
|useBeanValidation|Use BeanValidation API annotations| |true|
|
||||
|useOptional|Use Optional container for optional parameters| |false|
|
||||
|useSpringController|Annotate the generated API as a Spring Controller| |false|
|
||||
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
|
||||
|useTags|use tags for creating interface and controller classnames| |false|
|
||||
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
|
||||
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|
||||
|
@ -42,7 +42,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false|
|
||||
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|
||||
|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true|
|
||||
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd><dt>**springfox**</dt><dd>Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x.</dd><dt>**springdoc**</dt><dd>Generate an OpenAPI 3 specification using SpringDoc.</dd></dl>|springdoc|
|
||||
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd><dt>**springfox**</dt><dd>Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.</dd><dt>**springdoc**</dt><dd>Generate an OpenAPI 3 specification using SpringDoc.</dd></dl>|springdoc|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
|
||||
|fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false|
|
||||
@ -54,7 +54,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||
|invokerPackage|root package for generated code| |org.openapitools.api|
|
||||
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application using the SpringFox integration.</dd><dt>**spring-mvc**</dt><dd>Spring-MVC Server application using the SpringFox integration.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd></dl>|spring-boot|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd></dl>|spring-boot|
|
||||
|licenseName|The name of the license| |Unlicense|
|
||||
|licenseUrl|The URL of the license| |http://unlicense.org|
|
||||
|modelPackage|package for generated models| |org.openapitools.model|
|
||||
@ -77,13 +77,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|swaggerDocketConfig|Generate Spring OpenAPI Docket configuration class.| |false|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|title|server title name or client service name| |OpenAPI Spring|
|
||||
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|
||||
|useBeanValidation|Use BeanValidation API annotations| |true|
|
||||
|useOptional|Use Optional container for optional parameters| |false|
|
||||
|useSpringController|Annotate the generated API as a Spring Controller| |false|
|
||||
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
|
||||
|useTags|use tags for creating interface and controller classnames| |false|
|
||||
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
|
||||
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|
||||
|
@ -119,7 +119,7 @@ public class JavaCamelServerCodegen extends SpringCodegen implements BeanValidat
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("openapi2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator),
|
||||
"OpenAPI2SpringBoot.java"));
|
||||
"OpenApiGeneratorApplication.java"));
|
||||
|
||||
if (!interfaceOnly) {
|
||||
apiTemplateFiles.put("routesImpl.mustache", "RoutesImpl.java");
|
||||
|
@ -20,6 +20,12 @@ package org.openapitools.codegen.languages;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@ -31,13 +37,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
@ -50,8 +49,10 @@ import org.openapitools.codegen.CodegenSecurity;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
|
||||
import org.openapitools.codegen.languages.features.OptionalFeatures;
|
||||
import org.openapitools.codegen.languages.features.PerformBeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.SwaggerUIFeatures;
|
||||
import org.openapitools.codegen.meta.features.DocumentationFeature;
|
||||
import org.openapitools.codegen.meta.features.GlobalFeature;
|
||||
import org.openapitools.codegen.meta.features.ParameterFeature;
|
||||
@ -65,7 +66,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, PerformBeanValidationFeatures, OptionalFeatures {
|
||||
implements BeanValidationFeatures, PerformBeanValidationFeatures, OptionalFeatures, SwaggerUIFeatures {
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(SpringCodegen.class);
|
||||
|
||||
public static final String TITLE = "title";
|
||||
@ -83,11 +84,9 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String REACTIVE = "reactive";
|
||||
public static final String RESPONSE_WRAPPER = "responseWrapper";
|
||||
public static final String USE_TAGS = "useTags";
|
||||
public static final String SPRING_MVC_LIBRARY = "spring-mvc";
|
||||
public static final String SPRING_BOOT = "spring-boot";
|
||||
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";
|
||||
public static final String SPRING_CONTROLLER = "useSpringController";
|
||||
public static final String HATEOAS = "hateoas";
|
||||
@ -113,7 +112,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean performBeanValidation = false;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean openapiDocketConfig = false;
|
||||
protected boolean apiFirst = false;
|
||||
protected boolean useOptional = false;
|
||||
protected boolean virtualService = false;
|
||||
@ -121,6 +119,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean returnSuccessCode = false;
|
||||
protected boolean unhandledException = false;
|
||||
protected boolean useSpringController = false;
|
||||
protected boolean useSwaggerUI = true;
|
||||
|
||||
public SpringCodegen() {
|
||||
super();
|
||||
@ -185,8 +184,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS,
|
||||
"Skip header parameters in the generated API methods using @ApiImplicitParams annotation.",
|
||||
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
|
||||
@ -199,11 +196,13 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(UNHANDLED_EXCEPTION_HANDLING,
|
||||
"Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).",
|
||||
unhandledException));
|
||||
cliOptions.add(CliOption.newBoolean(USE_SWAGGER_UI,
|
||||
"Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies",
|
||||
useSwaggerUI));
|
||||
|
||||
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.");
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
|
||||
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
|
||||
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
|
||||
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
|
||||
setLibrary(SPRING_BOOT);
|
||||
final CliOption library = new CliOption(CodegenConstants.LIBRARY, CodegenConstants.LIBRARY_DESC)
|
||||
.defaultValue(SPRING_BOOT);
|
||||
@ -250,6 +249,16 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
return supportedLibraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the selected {@link DocumentationProviderFeatures.DocumentationProvider} requires us to bootstrap and
|
||||
* configure swagger-ui by ourselves. Springdoc, for example ships its own swagger-ui integration.
|
||||
*
|
||||
* @return true if the selected DocumentationProvider requires us to bootstrap swagger-ui.
|
||||
*/
|
||||
private boolean selectedDocumentationProviderRequiresSwaggerUiBootstrap() {
|
||||
return getDocumentationProvider().equals(DocumentationProvider.SPRINGFOX) || getDocumentationProvider().equals(DocumentationProvider.SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
final List<Pair<String, String>> configOptions = additionalProperties.entrySet().stream()
|
||||
@ -285,6 +294,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
super.processOpts();
|
||||
|
||||
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
|
||||
LOGGER.warn("The springfox documentation provider is deprecated for removal. Use the springdoc provider instead.");
|
||||
}
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
// TODO: add doc templates
|
||||
@ -367,11 +380,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setImplicitHeaders(Boolean.parseBoolean(additionalProperties.get(IMPLICIT_HEADERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(OPENAPI_DOCKET_CONFIG)) {
|
||||
this.setOpenapiDocketConfig(
|
||||
Boolean.parseBoolean(additionalProperties.get(OPENAPI_DOCKET_CONFIG).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(API_FIRST)) {
|
||||
this.setApiFirst(Boolean.parseBoolean(additionalProperties.get(API_FIRST).toString()));
|
||||
}
|
||||
@ -389,6 +397,16 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setReturnSuccessCode(Boolean.parseBoolean(additionalProperties.get(RETURN_SUCCESS_CODE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_SWAGGER_UI)) {
|
||||
this.setUseSwaggerUI(convertPropertyToBoolean(USE_SWAGGER_UI));
|
||||
}
|
||||
|
||||
if (getDocumentationProvider().equals(DocumentationProvider.NONE)) {
|
||||
this.setUseSwaggerUI(false);
|
||||
}
|
||||
|
||||
writePropertyBack(USE_SWAGGER_UI, useSwaggerUI);
|
||||
|
||||
if (additionalProperties.containsKey(UNHANDLED_EXCEPTION_HANDLING)) {
|
||||
this.setUnhandledException(
|
||||
Boolean.parseBoolean(additionalProperties.get(UNHANDLED_EXCEPTION_HANDLING).toString()));
|
||||
@ -422,27 +440,20 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
if (!interfaceOnly) {
|
||||
if (SPRING_BOOT.equals(library)) {
|
||||
if (useSwaggerUI && selectedDocumentationProviderRequiresSwaggerUiBootstrap()) {
|
||||
supportingFiles.add(new SupportingFile("swagger-ui.mustache", "src/main/resources/static", "swagger-ui.html"));
|
||||
}
|
||||
// rename template to SpringBootApplication.mustache
|
||||
supportingFiles.add(new SupportingFile("openapi2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator),
|
||||
"OpenAPI2SpringBoot.java"));
|
||||
"OpenApiGeneratorApplication.java"));
|
||||
supportingFiles.add(new SupportingFile("SpringBootTest.mustache",
|
||||
(testFolder + File.separator + basePackage).replace(".", java.io.File.separator),
|
||||
"OpenApiGeneratorApplicationTests.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator),
|
||||
"RFC3339DateFormat.java"));
|
||||
}
|
||||
if (SPRING_MVC_LIBRARY.equals(library)) {
|
||||
supportingFiles.add(new SupportingFile("webApplication.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
"WebApplication.java"));
|
||||
supportingFiles.add(new SupportingFile("webMvcConfiguration.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
"WebMvcConfiguration.java"));
|
||||
supportingFiles.add(new SupportingFile("openapiUiConfiguration.mustache",
|
||||
(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"));
|
||||
}
|
||||
if (SPRING_CLOUD_LIBRARY.equals(library)) {
|
||||
supportingFiles.add(new SupportingFile("apiKeyRequestInterceptor.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
@ -462,19 +473,14 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
"HomeController.java"));
|
||||
if (!reactive && !apiFirst && this.openapiDocketConfig) {
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache",
|
||||
("src/main/resources").replace("/", java.io.File.separator), "openapi.yaml"));
|
||||
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider()) && !reactive && !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"));
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
"SpringFoxConfiguration.java"));
|
||||
}
|
||||
}
|
||||
} else if (openapiDocketConfig && !SPRING_CLOUD_LIBRARY.equals(library) && !reactive && !apiFirst) {
|
||||
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
|
||||
"OpenAPIDocumentationConfig.java"));
|
||||
}
|
||||
|
||||
if (!SPRING_CLOUD_LIBRARY.equals(library)) {
|
||||
@ -570,7 +576,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co,
|
||||
Map<String, List<CodegenOperation>> operations) {
|
||||
if ((SPRING_BOOT.equals(library) || SPRING_MVC_LIBRARY.equals(library)) && !useTags) {
|
||||
if ((SPRING_BOOT.equals(library) && !useTags)) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
@ -868,10 +874,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.implicitHeaders = implicitHeaders;
|
||||
}
|
||||
|
||||
public void setOpenapiDocketConfig(boolean openapiDocketConfig) {
|
||||
this.openapiDocketConfig = openapiDocketConfig;
|
||||
}
|
||||
|
||||
public void setApiFirst(boolean apiFirst) {
|
||||
this.apiFirst = apiFirst;
|
||||
}
|
||||
@ -1008,4 +1010,9 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public void setUseOptional(boolean useOptional) {
|
||||
this.useOptional = useOptional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseSwaggerUI(boolean useSwaggerUI) {
|
||||
this.useSwaggerUI = useSwaggerUI;
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ package org.openapitools.codegen.languages.features;
|
||||
public interface BeanValidationExtendedFeatures {
|
||||
|
||||
// Language (implementing Client/Server) supports automatic BeanValidation (1.1)
|
||||
public static final String USE_BEANVALIDATION_FEATURE = "useBeanValidationFeature";
|
||||
String USE_BEANVALIDATION_FEATURE = "useBeanValidationFeature";
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature);
|
||||
void setUseBeanValidationFeature(boolean useBeanValidationFeature);
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ package org.openapitools.codegen.languages.features;
|
||||
public interface BeanValidationFeatures {
|
||||
|
||||
// Language supports generating BeanValidation-Annotations
|
||||
public static final String USE_BEANVALIDATION = "useBeanValidation";
|
||||
String USE_BEANVALIDATION = "useBeanValidation";
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation);
|
||||
void setUseBeanValidation(boolean useBeanValidation);
|
||||
|
||||
}
|
||||
|
@ -23,25 +23,25 @@ package org.openapitools.codegen.languages.features;
|
||||
public interface CXFServerFeatures
|
||||
extends CXFFeatures, SwaggerFeatures, SpringFeatures, JbossFeature, BeanValidationExtendedFeatures, SwaggerUIFeatures {
|
||||
|
||||
public static final String USE_WADL_FEATURE = "useWadlFeature";
|
||||
String USE_WADL_FEATURE = "useWadlFeature";
|
||||
|
||||
public static final String USE_MULTIPART_FEATURE = "useMultipartFeature";
|
||||
String USE_MULTIPART_FEATURE = "useMultipartFeature";
|
||||
|
||||
public static final String ADD_CONSUMES_PRODUCES_JSON = "addConsumesProducesJson";
|
||||
String ADD_CONSUMES_PRODUCES_JSON = "addConsumesProducesJson";
|
||||
|
||||
public static final String USE_ANNOTATED_BASE_PATH = "useAnnotatedBasePath";
|
||||
String USE_ANNOTATED_BASE_PATH = "useAnnotatedBasePath";
|
||||
|
||||
public static final String GENERATE_NON_SPRING_APPLICATION = "generateNonSpringApplication";
|
||||
String GENERATE_NON_SPRING_APPLICATION = "generateNonSpringApplication";
|
||||
|
||||
public static final String LOAD_TEST_DATA_FROM_FILE = "loadTestDataFromFile";
|
||||
String LOAD_TEST_DATA_FROM_FILE = "loadTestDataFromFile";
|
||||
|
||||
public void setUseWadlFeature(boolean useWadlFeature);
|
||||
void setUseWadlFeature(boolean useWadlFeature);
|
||||
|
||||
public void setUseMultipartFeature(boolean useMultipartFeature);
|
||||
void setUseMultipartFeature(boolean useMultipartFeature);
|
||||
|
||||
public void setAddConsumesProducesJson(boolean addConsumesProducesJson);
|
||||
void setAddConsumesProducesJson(boolean addConsumesProducesJson);
|
||||
|
||||
public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath);
|
||||
void setUseAnnotatedBasePath(boolean useAnnotatedBasePath);
|
||||
|
||||
public void setGenerateNonSpringApplication(boolean generateNonSpringApplication);
|
||||
void setGenerateNonSpringApplication(boolean generateNonSpringApplication);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public interface DocumentationProviderFeatures {
|
||||
SWAGGER2("swagger2DocumentationProvider", "Generate an OpenAPI 3 specification using Swagger-Core 2.x.",
|
||||
AnnotationLibrary.SWAGGER2, AnnotationLibrary.SWAGGER2),
|
||||
|
||||
SPRINGFOX("springFoxDocumentationProvider", "Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x.",
|
||||
SPRINGFOX("springFoxDocumentationProvider", "Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.",
|
||||
AnnotationLibrary.SWAGGER1, AnnotationLibrary.SWAGGER1),
|
||||
|
||||
SPRINGDOC("springDocDocumentationProvider", "Generate an OpenAPI 3 specification using SpringDoc.",
|
||||
|
@ -19,8 +19,8 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface GzipFeatures {
|
||||
|
||||
public static final String USE_GZIP_FEATURE = "useGzipFeature";
|
||||
String USE_GZIP_FEATURE = "useGzipFeature";
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature);
|
||||
void setUseGzipFeature(boolean useGzipFeature);
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface GzipTestFeatures {
|
||||
|
||||
public static final String USE_GZIP_FEATURE_FOR_TESTS = "useGzipFeatureForTests";
|
||||
String USE_GZIP_FEATURE_FOR_TESTS = "useGzipFeatureForTests";
|
||||
|
||||
public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests);
|
||||
void setUseGzipFeatureForTests(boolean useGzipFeatureForTests);
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface JbossFeature {
|
||||
|
||||
public static final String GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR = "generateJbossDeploymentDescriptor";
|
||||
String GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR = "generateJbossDeploymentDescriptor";
|
||||
|
||||
public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor);
|
||||
void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor);
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface LoggingFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String USE_LOGGING_FEATURE = "useLoggingFeature";
|
||||
String USE_LOGGING_FEATURE = "useLoggingFeature";
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature);
|
||||
void setUseLoggingFeature(boolean useLoggingFeature);
|
||||
|
||||
}
|
||||
|
@ -18,8 +18,9 @@
|
||||
package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface LoggingTestFeatures {
|
||||
public static final String USE_LOGGING_FEATURE_FOR_TESTS = "useLoggingFeatureForTests";
|
||||
|
||||
public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests);
|
||||
String USE_LOGGING_FEATURE_FOR_TESTS = "useLoggingFeatureForTests";
|
||||
|
||||
void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests);
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ package org.openapitools.codegen.languages.features;
|
||||
public interface PerformBeanValidationFeatures {
|
||||
|
||||
// Language supports performing BeanValidation
|
||||
public static final String PERFORM_BEANVALIDATION = "performBeanValidation";
|
||||
String PERFORM_BEANVALIDATION = "performBeanValidation";
|
||||
|
||||
public void setPerformBeanValidation(boolean performBeanValidation);
|
||||
void setPerformBeanValidation(boolean performBeanValidation);
|
||||
|
||||
}
|
||||
|
@ -19,17 +19,16 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface SpringFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String GENERATE_SPRING_APPLICATION = "generateSpringApplication";
|
||||
String GENERATE_SPRING_APPLICATION = "generateSpringApplication";
|
||||
|
||||
public static final String GENERATE_SPRING_BOOT_APPLICATION = "generateSpringBootApplication";
|
||||
String GENERATE_SPRING_BOOT_APPLICATION = "generateSpringBootApplication";
|
||||
|
||||
public static final String USE_SPRING_ANNOTATION_CONFIG = "useSpringAnnotationConfig";
|
||||
String USE_SPRING_ANNOTATION_CONFIG = "useSpringAnnotationConfig";
|
||||
|
||||
public void setGenerateSpringApplication(boolean useGenerateSpringApplication);
|
||||
void setGenerateSpringApplication(boolean useGenerateSpringApplication);
|
||||
|
||||
public void setGenerateSpringBootApplication(boolean generateSpringBootApplication);
|
||||
|
||||
public void setUseSpringAnnotationConfig(boolean useSpringAnnotationConfig);
|
||||
void setGenerateSpringBootApplication(boolean generateSpringBootApplication);
|
||||
|
||||
void setUseSpringAnnotationConfig(boolean useSpringAnnotationConfig);
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface SwaggerFeatures {
|
||||
|
||||
public static final String USE_SWAGGER_FEATURE = "useSwaggerFeature";
|
||||
String USE_SWAGGER_FEATURE = "useSwaggerFeature";
|
||||
|
||||
public void setUseSwaggerFeature(boolean useSwaggerFeature);
|
||||
void setUseSwaggerFeature(boolean useSwaggerFeature);
|
||||
|
||||
}
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
package org.openapitools.codegen.languages.features;
|
||||
|
||||
public interface SwaggerUIFeatures extends CXFFeatures {
|
||||
public interface SwaggerUIFeatures {
|
||||
|
||||
public static final String USE_SWAGGER_UI = "useSwaggerUI";
|
||||
String USE_SWAGGER_UI = "useSwaggerUI";
|
||||
|
||||
public void setUseSwaggerUI(boolean useSwaggerUI);
|
||||
void setUseSwaggerUI(boolean useSwaggerUI);
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package org.openapitools.codegen.languages.features;
|
||||
public interface UseGenericResponseFeatures {
|
||||
|
||||
// Language supports generating generic Jaxrs or native return types
|
||||
public static final String USE_GENERIC_RESPONSE = "useGenericResponse";
|
||||
String USE_GENERIC_RESPONSE = "useGenericResponse";
|
||||
|
||||
public void setUseGenericResponse(boolean useGenericResponse);
|
||||
void setUseGenericResponse(boolean useGenericResponse);
|
||||
}
|
||||
|
@ -1,36 +1,34 @@
|
||||
package {{configPackage}};
|
||||
|
||||
{{^springFoxDocumentationProvider}}
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
{{#sourceDocumentationProvider}}
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
import org.springframework.stereotype.Controller;
|
||||
{{^springFoxDocumentationProvider}}
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
{{^springFoxDocumentationProvider}}
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
{{/useSwaggerUI}}
|
||||
{{#reactive}}
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
{{/reactive}}
|
||||
|
||||
{{^springFoxDocumentationProvider}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#reactive}}
|
||||
import java.net.URI;
|
||||
{{/reactive}}
|
||||
{{^springFoxDocumentationProvider}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
import java.nio.charset.Charset;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#reactive}}
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
@ -42,8 +40,8 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
{{#sourceDocumentationProvider}}
|
||||
|
||||
{{^springFoxDocumentationProvider}}
|
||||
private static YAMLMapper yamlMapper = new YAMLMapper();
|
||||
|
||||
@Value("classpath:/openapi.yaml")
|
||||
@ -67,23 +65,40 @@ public class HomeController {
|
||||
public Object openapiJson() throws IOException {
|
||||
return yamlMapper.readValue(openapiContent(), Object.class);
|
||||
}
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
{{^springDocDocumentationProvider}}
|
||||
|
||||
{{#sourceDocumentationProvider}}
|
||||
static final String API_DOCS_PATH = "/openapi.json";
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#springFoxDocumentationProvider}}
|
||||
static final String API_DOCS_PATH = "/v2/api-docs";
|
||||
{{/springFoxDocumentationProvider}}
|
||||
|
||||
@GetMapping(value = "/swagger-config.yaml", produces = "text/plain")
|
||||
@ResponseBody
|
||||
public String swaggerConfig() {
|
||||
return "url: " + API_DOCS_PATH + "\n";
|
||||
}
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{#reactive}}
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> index() {
|
||||
return route(
|
||||
GET("/"),
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("{{#springFoxDocumentationProvider}}swagger-ui.html{{/springFoxDocumentationProvider}}{{^springFoxDocumentationProvider}}swagger-ui/index.html?url=../openapi.json{{/springFoxDocumentationProvider}}")).build()
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build()
|
||||
);
|
||||
}
|
||||
{{/reactive}}
|
||||
{{^reactive}}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:{{#springFoxDocumentationProvider}}swagger-ui.html{{/springFoxDocumentationProvider}}{{^springFoxDocumentationProvider}}swagger-ui/index.html?url=../openapi.json{{/springFoxDocumentationProvider}}";
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
{{/reactive}}
|
||||
{{/useSwaggerUI}}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -2,23 +2,44 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
{{#springFoxDocumentationProvider}}
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springfox](https://github.com/springfox/springfox).
|
||||
Springfox will generate an OpenAPI v2 (fka Swagger RESTful API Documentation Specification) specification based on the
|
||||
generated Controller and Model classes. The specification is available to download using the following url:
|
||||
http://localhost:{{serverPort}}/v2/api-docs/
|
||||
|
||||
**HEADS-UP**: Springfox is deprecated for removal in version 6.0.0 of openapi-generator. The project seems to be no longer
|
||||
maintained (last commit is of Oct 14, 2020). It works with Spring Boot 2.5.x but not with 2.6. Spring Boot 2.5 is
|
||||
supported until 2022-05-19. Users of openapi-generator should migrate to the springdoc documentation provider which is,
|
||||
as an added bonus, OpenAPI v3 compatible.
|
||||
|
||||
{{/springFoxDocumentationProvider}}
|
||||
|
||||
{{#springDocDocumentationProvider}}
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:{{serverPort}}/v3/api-docs/
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
|
||||
The OpenAPI specification used to generate this project is available to download using the following url:
|
||||
http://localhost:{{serverPort}}/openapi.json
|
||||
{{/sourceDocumentationProvider}}
|
||||
|
||||
Start your server as a simple java application
|
||||
{{#useSwaggerUI}}
|
||||
|
||||
{{^reactive}}
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:{{serverPort}}/
|
||||
http://localhost:{{serverPort}}/swagger-ui.html
|
||||
|
||||
{{/reactive}}
|
||||
{{/useSwaggerUI}}
|
||||
Change default port value in application.properties{{/interfaceOnly}}{{#interfaceOnly}}
|
||||
# OpenAPI generated API stub
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package {{basePackage}};
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
{{#springFoxDocumentationProvider}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/springFoxDocumentationProvider}}
|
||||
server.port={{serverPort}}
|
||||
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
|
@ -1,73 +1,20 @@
|
||||
package {{basePackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
{{#openApiNullable}}
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
{{/openApiNullable}}
|
||||
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;
|
||||
{{^springFoxDocumentationProvider}}
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
{{^springFoxDocumentationProvider}}
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
{{/reactive}}
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer webConfigurer() {
|
||||
return new Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
{{^springFoxDocumentationProvider}}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/springFoxDocumentationProvider}}
|
||||
};
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
{{#openApiNullable}}
|
||||
@ -77,4 +24,4 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
{{/openApiNullable}}
|
||||
|
||||
}
|
||||
}
|
@ -25,6 +25,9 @@
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
{{/useSwaggerUI}}
|
||||
</properties>
|
||||
{{#parentOverridden}}
|
||||
<parent>
|
||||
@ -37,7 +40,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>{{#springFoxDocumentationProvider}}2.5.8{{/springFoxDocumentationProvider}}{{^springFoxDocumentationProvider}}2.6.2{{/springFoxDocumentationProvider}}</version>
|
||||
<version>{{#springFoxDocumentationProvider}}2.5.8{{/springFoxDocumentationProvider}}{{^springFoxDocumentationProvider}}2.6.3{{/springFoxDocumentationProvider}}</version>
|
||||
</parent>
|
||||
{{/parentOverridden}}
|
||||
<build>
|
||||
@ -94,11 +97,20 @@
|
||||
</dependency>
|
||||
{{#springDocDocumentationProvider}}
|
||||
<!--SpringDoc dependencies -->
|
||||
{{#useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
{{/useSwaggerUI}}
|
||||
{{^useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
{{/useSwaggerUI}}
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies -->
|
||||
@ -108,6 +120,19 @@
|
||||
<version>${springfox.version}</version>
|
||||
</dependency>
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
{{^springDocDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{/useSwaggerUI}}
|
||||
{{^springFoxDocumentationProvider}}
|
||||
{{^springDocDocumentationProvider}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@ -204,5 +229,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -0,0 +1,60 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="webjars/swagger-ui/swagger-ui.css" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="webjars/swagger-ui/swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="webjars/swagger-ui/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Begin Swagger UI call region
|
||||
const ui = SwaggerUIBundle({
|
||||
configUrl: 'swagger-config.yaml',
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
});
|
||||
// End Swagger UI call region
|
||||
|
||||
window.ui = ui;
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +0,0 @@
|
||||
# OpenAPI generated server
|
||||
|
||||
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.
|
||||
|
||||
{{#springFoxDocumentationProvider}}
|
||||
The underlying library integrating OpenAPI to Spring-MVC is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
{{/springFoxDocumentationProvider}}
|
||||
You can view the server in swagger-ui by pointing to
|
||||
http://localhost:{{serverPort}}{{contextPath}}{{^contextPath}}/{{/contextPath}}/
|
@ -1,38 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.util.StdDateFormat;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class RFC3339DateFormat extends DateFormat {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");
|
||||
|
||||
private final StdDateFormat fmt = new StdDateFormat()
|
||||
.withTimeZone(TIMEZONE_Z)
|
||||
.withColonInTimeZone(true);
|
||||
|
||||
public RFC3339DateFormat() {
|
||||
this.calendar = new GregorianCalendar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date parse(String source, ParsePosition pos) {
|
||||
return fmt.parse(source, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
return fmt.format(date, toAppendTo, fieldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{{#springFoxDocumentationProvider}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/springFoxDocumentationProvider}}
|
@ -1 +0,0 @@
|
||||
/
|
@ -1,126 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
{{#threetenbp}}
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
{{/threetenbp}}
|
||||
{{#openApiNullable}}
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
{{/openApiNullable}}
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
{{#springFoxDocumentationProvider}}
|
||||
import org.springframework.context.annotation.Import;
|
||||
{{/springFoxDocumentationProvider}}
|
||||
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;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
{{#threetenbp}}
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
{{/threetenbp}}
|
||||
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"{{apiPackage}}", "{{configPackage}}"})
|
||||
@EnableWebMvc
|
||||
@PropertySource("classpath:application.properties")
|
||||
{{#springFoxDocumentationProvider}}
|
||||
@Import(OpenAPIDocumentationConfig.class)
|
||||
{{/springFoxDocumentationProvider}}
|
||||
public class OpenAPIUiConfiguration 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 addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(new PageableHandlerMethodArgumentResolver());
|
||||
super.addArgumentResolvers(argumentResolvers);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
{{^springFoxDocumentationProvider}}
|
||||
if (!registry.hasMappingForPattern("/swagger-ui/**")) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/springFoxDocumentationProvider}}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
{{#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)
|
||||
{{#openApiNullable}}.modulesToInstall({{#threetenbp}}module, {{/threetenbp}}new JsonNullableModule()){{/openApiNullable}}
|
||||
{{^openApiNullable}}{{#threetenbp}}.modulesToInstall(module){{/threetenbp}}{{/openApiNullable}}
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
return builder().build();
|
||||
}
|
||||
}
|
@ -1,303 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
{{#parentOverridden}}
|
||||
<parent>
|
||||
<groupId>{{{parentGroupId}}}</groupId>
|
||||
<artifactId>{{{parentArtifactId}}}</artifactId>
|
||||
<version>{{{parentVersion}}}</version>
|
||||
</parent>
|
||||
{{/parentOverridden}}
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webAppConfig>
|
||||
<contextPath>{{contextPath}}{{^contextPath}}/{{/contextPath}}</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<stopWait>10</stopWait>
|
||||
<httpConnector>
|
||||
<port>{{serverPort}}</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
{{#useBeanValidation}}
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
{{/useBeanValidation}}
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</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>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
<version>${jakarta.xml.bind-version}</version>
|
||||
</dependency>
|
||||
{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{^springFoxDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
{{#oas3}}
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
{{/oas3}}
|
||||
{{^oas3}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
{{/oas3}}
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{#withXml}}
|
||||
<!-- XML processing: Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/withXml}}
|
||||
{{#joda}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#threetenbp}}
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>${jackson-threetenbp-version}</version>
|
||||
</dependency>
|
||||
{{/threetenbp}}
|
||||
{{#openApiNullable}}
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>jackson-databind-nullable</artifactId>
|
||||
<version>${jackson-databind-nullable-version}</version>
|
||||
</dependency>
|
||||
{{/openApiNullable}}
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/useBeanValidation}}
|
||||
{{#hateoas}}
|
||||
<!-- Spring HATEOAS -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
<version>1.0.1.RELEASE</version>
|
||||
</dependency>
|
||||
{{/hateoas}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
<version>2.0.11.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-databind-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
|
||||
<jakarta.xml.bind-version>2.3.3</jakarta.xml.bind-version>
|
||||
<jetty-version>9.2.15.v20160210</jetty-version>
|
||||
<slf4j-version>1.7.21</slf4j-version>
|
||||
<junit-version>4.13.1</junit-version>
|
||||
<servlet-api-version>4.0.4</servlet-api-version>
|
||||
<springfox-version>2.9.2</springfox-version>
|
||||
<jackson-version>2.9.9</jackson-version>
|
||||
<jackson-threetenbp-version>2.8.4</jackson-threetenbp-version>
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>2.0.2</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
<spring-version>4.3.20.RELEASE</spring-version>
|
||||
{{#openApiNullable}}
|
||||
<jackson-databind-nullable-version>0.2.2</jackson-databind-nullable-version>
|
||||
{{/openApiNullable}}
|
||||
<jackson-databind-version>2.9.8</jackson-databind-version>
|
||||
<swagger-core-version>{{#oas3}}2.1.11{{/oas3}}{{^oas3}}1.6.3{{/oas3}}</swagger-core-version>
|
||||
</properties>
|
||||
</project>
|
@ -1,23 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class WebApplication extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class[] { OpenAPIUiConfiguration.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class<?>[] { WebMvcConfiguration.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
@Override
|
||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||
configurer.enable();
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ import javax.servlet.ServletContext;
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class OpenAPIDocumentationConfig {
|
||||
public class SpringFoxConfiguration {
|
||||
|
||||
ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
|
@ -775,7 +775,7 @@ public class SpringCodegenTest {
|
||||
}
|
||||
|
||||
/**define the destinationFilename*/
|
||||
private final static String DESTINATIONFILE = "OpenAPIDocumentationConfig.java";
|
||||
private final static String DESTINATIONFILE = "SpringFoxConfiguration.java";
|
||||
/**define the templateFile*/
|
||||
private final static String TEMPLATEFILE = "openapiDocumentationConfig.mustache";
|
||||
|
||||
@ -787,14 +787,14 @@ public class SpringCodegenTest {
|
||||
public void testConfigFileGeneration() {
|
||||
|
||||
final SpringCodegen codegen = new SpringCodegen();
|
||||
|
||||
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, "springfox");
|
||||
codegen.additionalProperties().put(SpringCodegen.INTERFACE_ONLY, false);
|
||||
codegen.additionalProperties().put(SpringCodegen.SPRING_CLOUD_LIBRARY, "spring-cloud");
|
||||
codegen.additionalProperties().put(SpringCodegen.OPENAPI_DOCKET_CONFIG, true);
|
||||
codegen.additionalProperties().put(SpringCodegen.REACTIVE, false);
|
||||
codegen.additionalProperties().put(SpringCodegen.API_FIRST, false);
|
||||
|
||||
codegen.processOpts();
|
||||
|
||||
final List<SupportingFile> supList = codegen.supportingFiles();
|
||||
String tmpFile;
|
||||
String desFile;
|
||||
|
16
pom.xml
16
pom.xml
@ -1036,18 +1036,6 @@
|
||||
<module>samples/client/petstore/go</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>spring-mvc</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>springboot-beanvalidation</id>
|
||||
<activation>
|
||||
@ -1186,10 +1174,6 @@
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs/jersey2</module>
|
||||
<module>samples/server/petstore/jaxrs/jersey2-useTags</module>
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
<module>samples/server/petstore/spring-mvc-default-value</module>
|
||||
<module>samples/server/petstore/spring-mvc-j8-async</module>
|
||||
<module>samples/server/petstore/spring-mvc-j8-localdatetime</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/java-camel</module>
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
|
@ -10,6 +10,7 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springfox.version>2.9.2</springfox.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -34,6 +35,15 @@
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
@ -62,5 +72,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -62,5 +63,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -62,5 +63,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,6 +1,6 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/ApiUtil.java
|
||||
src/main/java/org/openapitools/api/PetApi.java
|
||||
@ -18,3 +18,4 @@ src/main/java/org/openapitools/model/Tag.java
|
||||
src/main/java/org/openapitools/model/User.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
||||
|
@ -2,15 +2,16 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:8080/v3/api-docs/
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
|
||||
Change default port value in application.properties
|
@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -37,7 +37,7 @@
|
||||
<!--SpringDoc dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<artifactId>springdoc-openapi-webmvc-core</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
<!-- @Nullable annotation -->
|
||||
@ -68,5 +68,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,63 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@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/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,8 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
@ -20,34 +10,4 @@ import java.nio.charset.Charset;
|
||||
@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);
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui/index.html?url=../openapi.json";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApi.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApiController.java
|
||||
@ -66,3 +66,4 @@ src/main/java/org/openapitools/model/User.java
|
||||
src/main/java/org/openapitools/model/XmlItem.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
||||
|
@ -2,15 +2,20 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:80/v3/api-docs/
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:80/
|
||||
http://localhost:80/swagger-ui.html
|
||||
|
||||
Change default port value in application.properties
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -63,5 +64,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,58 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@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/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,18 +1,10 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
@ -20,34 +12,9 @@ import java.nio.charset.Charset;
|
||||
@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);
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui/index.html?url=../openapi.json";
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApi.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApiController.java
|
||||
@ -72,3 +72,4 @@ src/main/java/org/openapitools/model/User.java
|
||||
src/main/java/org/openapitools/model/XmlItem.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
||||
|
@ -2,15 +2,20 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:80/v3/api-docs/
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:80/
|
||||
http://localhost:80/swagger-ui.html
|
||||
|
||||
Change default port value in application.properties
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -68,5 +69,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,63 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@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/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,10 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
@ -20,34 +12,9 @@ import java.nio.charset.Charset;
|
||||
@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);
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui/index.html?url=../openapi.json";
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApi.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApiController.java
|
||||
@ -66,3 +66,4 @@ src/main/java/org/openapitools/model/User.java
|
||||
src/main/java/org/openapitools/model/XmlItem.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
||||
|
@ -2,15 +2,20 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:80/v3/api-docs/
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:80/
|
||||
http://localhost:80/swagger-ui.html
|
||||
|
||||
Change default port value in application.properties
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -68,5 +69,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,63 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@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/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,10 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
@ -20,34 +12,9 @@ import java.nio.charset.Charset;
|
||||
@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);
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui/index.html?url=../openapi.json";
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApi.java
|
||||
src/main/java/org/openapitools/api/AnotherFakeApiController.java
|
||||
@ -72,3 +72,4 @@ src/main/java/org/openapitools/model/User.java
|
||||
src/main/java/org/openapitools/model/XmlItem.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
||||
|
@ -2,12 +2,20 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
|
||||
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
|
||||
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
|
||||
The specification is available to download using the following url:
|
||||
http://localhost:80/v3/api-docs/
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:80/swagger-ui.html
|
||||
|
||||
Change default port value in application.properties
|
@ -10,11 +10,12 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springdoc.version>1.6.4</springdoc.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -37,7 +38,7 @@
|
||||
<!--SpringDoc dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<artifactId>springdoc-openapi-webflux-ui</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
<!-- @Nullable annotation -->
|
||||
@ -68,5 +69,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,63 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,13 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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;
|
||||
@ -27,37 +18,12 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
|
||||
@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()
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
README.md
|
||||
pom.xml
|
||||
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
|
||||
src/main/java/org/openapitools/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/api/ApiUtil.java
|
||||
src/main/java/org/openapitools/api/PetApi.java
|
||||
src/main/java/org/openapitools/api/PetApiController.java
|
||||
src/main/java/org/openapitools/api/StoreApi.java
|
||||
src/main/java/org/openapitools/api/StoreApiController.java
|
||||
src/main/java/org/openapitools/api/UserApi.java
|
||||
src/main/java/org/openapitools/api/UserApiController.java
|
||||
src/main/java/org/openapitools/configuration/HomeController.java
|
||||
src/main/java/org/openapitools/model/Category.java
|
||||
src/main/java/org/openapitools/model/ModelApiResponse.java
|
||||
src/main/java/org/openapitools/model/Order.java
|
||||
src/main/java/org/openapitools/model/Pet.java
|
||||
src/main/java/org/openapitools/model/Tag.java
|
||||
src/main/java/org/openapitools/model/User.java
|
||||
src/main/resources/application.properties
|
||||
src/main/resources/openapi.yaml
|
||||
src/main/resources/static/swagger-ui.html
|
||||
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
|
@ -2,17 +2,18 @@
|
||||
|
||||
Spring Boot 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 SpringBoot framework.
|
||||
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
The OpenAPI specification used to generate this project is available to download using the following url:
|
||||
http://localhost:8080/openapi.json
|
||||
|
||||
Start your server as a simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:8080/swagger-ui.html
|
||||
|
||||
Change default port value in application.properties
|
@ -1,20 +1,20 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>spring-mvc-default-value</artifactId>
|
||||
<groupId>org.openapitools.openapi3</groupId>
|
||||
<artifactId>springboot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>spring-mvc-default-value</name>
|
||||
<version>1.0.0</version>
|
||||
<name>springboot</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springfox.version>2.9.2</springfox.version>
|
||||
<swagger-ui.version>4.4.1-1</swagger-ui.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.5.8</version>
|
||||
<version>2.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -34,11 +34,14 @@
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
</dependency>
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox.version}</version>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
@ -68,5 +71,10 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
@ -7,8 +7,6 @@ package org.openapitools.api;
|
||||
|
||||
import org.openapitools.model.ModelApiResponse;
|
||||
import org.openapitools.model.Pet;
|
||||
import java.util.Set;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -26,7 +24,6 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Validated
|
||||
@Api(value = "pet", description = "the pet API")
|
||||
public interface PetApi {
|
||||
|
||||
default Optional<NativeWebRequest> getRequest() {
|
||||
@ -36,34 +33,33 @@ public interface PetApi {
|
||||
/**
|
||||
* POST /pet : Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store (required)
|
||||
* @param pet Pet object that needs to be added to the store (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid input (status code 405)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Add a new pet to the store",
|
||||
nickname = "addPet",
|
||||
notes = "",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation"),
|
||||
@ApiResponse(code = 405, message = "Invalid input")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/pet",
|
||||
produces = { "application/xml", "application/json" },
|
||||
consumes = { "application/json", "application/xml" }
|
||||
)
|
||||
default ResponseEntity<Void> addPet(
|
||||
@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet body
|
||||
default ResponseEntity<Pet> addPet(
|
||||
@Valid @RequestBody Pet pet
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
ApiUtil.setExampleResponse(request, "application/json", exampleString);
|
||||
break;
|
||||
}
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
|
||||
String exampleString = "<Pet> <id>123456789</id> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> </tags> <status>aeiou</status> </Pet>";
|
||||
ApiUtil.setExampleResponse(request, "application/xml", exampleString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
@ -74,32 +70,15 @@ public interface PetApi {
|
||||
*
|
||||
* @param petId Pet id to delete (required)
|
||||
* @param apiKey (optional)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid pet value (status code 400)
|
||||
* @return Invalid pet value (status code 400)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Deletes a pet",
|
||||
nickname = "deletePet",
|
||||
notes = "",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation"),
|
||||
@ApiResponse(code = 400, message = "Invalid pet value")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.DELETE,
|
||||
value = "/pet/{petId}"
|
||||
)
|
||||
default ResponseEntity<Void> deletePet(
|
||||
@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) String apiKey
|
||||
@PathVariable("petId") Long petId,
|
||||
@RequestHeader(value = "api_key", required = false) String apiKey
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -114,36 +93,18 @@ public interface PetApi {
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid status value (status code 400)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Finds Pets by status",
|
||||
nickname = "findPetsByStatus",
|
||||
notes = "Multiple status values can be provided with comma separated strings",
|
||||
response = Pet.class,
|
||||
responseContainer = "List",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
|
||||
@ApiResponse(code = 400, message = "Invalid status value")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/pet/findByStatus",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<List<Pet>> findPetsByStatus(
|
||||
@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) List<String> status
|
||||
@NotNull @Valid @RequestParam(value = "status", required = true) List<String> status
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
ApiUtil.setExampleResponse(request, "application/json", exampleString);
|
||||
break;
|
||||
}
|
||||
@ -168,36 +129,18 @@ public interface PetApi {
|
||||
* or Invalid tag value (status code 400)
|
||||
* @deprecated
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Finds Pets by tags",
|
||||
nickname = "findPetsByTags",
|
||||
notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
|
||||
response = Pet.class,
|
||||
responseContainer = "Set",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "Set"),
|
||||
@ApiResponse(code = 400, message = "Invalid tag value")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/pet/findByTags",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<Set<Pet>> findPetsByTags(
|
||||
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) Set<String> tags
|
||||
default ResponseEntity<List<Pet>> findPetsByTags(
|
||||
@NotNull @Valid @RequestParam(value = "tags", required = true) List<String> tags
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
ApiUtil.setExampleResponse(request, "application/json", exampleString);
|
||||
break;
|
||||
}
|
||||
@ -222,33 +165,18 @@ public interface PetApi {
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Pet not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Find pet by ID",
|
||||
nickname = "getPetById",
|
||||
notes = "Returns a single pet",
|
||||
response = Pet.class,
|
||||
authorizations = {
|
||||
@Authorization(value = "api_key")
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Pet not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/pet/{petId}",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<Pet> getPetById(
|
||||
@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") Long petId
|
||||
@PathVariable("petId") Long petId
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
ApiUtil.setExampleResponse(request, "application/json", exampleString);
|
||||
break;
|
||||
}
|
||||
@ -267,38 +195,35 @@ public interface PetApi {
|
||||
/**
|
||||
* PUT /pet : Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store (required)
|
||||
* @param pet Pet object that needs to be added to the store (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Pet not found (status code 404)
|
||||
* or Validation exception (status code 405)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Update an existing pet",
|
||||
nickname = "updatePet",
|
||||
notes = "",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation"),
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Pet not found"),
|
||||
@ApiResponse(code = 405, message = "Validation exception")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.PUT,
|
||||
value = "/pet",
|
||||
produces = { "application/xml", "application/json" },
|
||||
consumes = { "application/json", "application/xml" }
|
||||
)
|
||||
default ResponseEntity<Void> updatePet(
|
||||
@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet body
|
||||
default ResponseEntity<Pet> updatePet(
|
||||
@Valid @RequestBody Pet pet
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
|
||||
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
|
||||
ApiUtil.setExampleResponse(request, "application/json", exampleString);
|
||||
break;
|
||||
}
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
|
||||
String exampleString = "<Pet> <id>123456789</id> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> </tags> <status>aeiou</status> </Pet>";
|
||||
ApiUtil.setExampleResponse(request, "application/xml", exampleString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
@ -312,30 +237,15 @@ public interface PetApi {
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return Invalid input (status code 405)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "Updates a pet in the store with form data",
|
||||
nickname = "updatePetWithForm",
|
||||
notes = "",
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 405, message = "Invalid input")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/pet/{petId}",
|
||||
consumes = { "application/x-www-form-urlencoded" }
|
||||
)
|
||||
default ResponseEntity<Void> updatePetWithForm(
|
||||
@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "Updated name of the pet") @Valid @RequestPart(value = "name", required = false) String name,
|
||||
@ApiParam(value = "Updated status of the pet") @Valid @RequestPart(value = "status", required = false) String status
|
||||
@PathVariable("petId") Long petId,
|
||||
@Valid @RequestPart(value = "name", required = false) String name,
|
||||
@Valid @RequestPart(value = "status", required = false) String status
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -350,22 +260,6 @@ public interface PetApi {
|
||||
* @param file file to upload (optional)
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "pet" },
|
||||
value = "uploads an image",
|
||||
nickname = "uploadFile",
|
||||
notes = "",
|
||||
response = ModelApiResponse.class,
|
||||
authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class)
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/pet/{petId}/uploadImage",
|
||||
@ -373,9 +267,9 @@ public interface PetApi {
|
||||
consumes = { "multipart/form-data" }
|
||||
)
|
||||
default ResponseEntity<ModelApiResponse> uploadFile(
|
||||
@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false) String additionalMetadata,
|
||||
@ApiParam(value = "file to upload") @RequestPart(value = "file", required = false) MultipartFile file
|
||||
@PathVariable("petId") Long petId,
|
||||
@Valid @RequestPart(value = "additionalMetadata", required = false) String additionalMetadata,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
@ -9,7 +9,7 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Controller
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/}")
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
|
||||
public class PetApiController implements PetApi {
|
||||
|
||||
private final NativeWebRequest request;
|
@ -7,7 +7,6 @@ package org.openapitools.api;
|
||||
|
||||
import java.util.Map;
|
||||
import org.openapitools.model.Order;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -25,7 +24,6 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Validated
|
||||
@Api(value = "store", description = "the store API")
|
||||
public interface StoreApi {
|
||||
|
||||
default Optional<NativeWebRequest> getRequest() {
|
||||
@ -33,29 +31,19 @@ public interface StoreApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /store/order/{order_id} : Delete purchase order by ID
|
||||
* DELETE /store/order/{orderId} : Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
*
|
||||
* @param orderId ID of the order that needs to be deleted (required)
|
||||
* @return Invalid ID supplied (status code 400)
|
||||
* or Order not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "store" },
|
||||
value = "Delete purchase order by ID",
|
||||
nickname = "deleteOrder",
|
||||
notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Order not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.DELETE,
|
||||
value = "/store/order/{order_id}"
|
||||
value = "/store/order/{orderId}"
|
||||
)
|
||||
default ResponseEntity<Void> deleteOrder(
|
||||
@ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("order_id") String orderId
|
||||
@PathVariable("orderId") String orderId
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -68,20 +56,6 @@ public interface StoreApi {
|
||||
*
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "store" },
|
||||
value = "Returns pet inventories by status",
|
||||
nickname = "getInventory",
|
||||
notes = "Returns a map of status codes to quantities",
|
||||
response = Integer.class,
|
||||
responseContainer = "Map",
|
||||
authorizations = {
|
||||
@Authorization(value = "api_key")
|
||||
}
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Map.class, responseContainer = "Map")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/store/inventory",
|
||||
@ -96,7 +70,7 @@ public interface StoreApi {
|
||||
|
||||
|
||||
/**
|
||||
* GET /store/order/{order_id} : Find purchase order by ID
|
||||
* GET /store/order/{orderId} : Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
*
|
||||
* @param orderId ID of pet that needs to be fetched (required)
|
||||
@ -104,25 +78,13 @@ public interface StoreApi {
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Order not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "store" },
|
||||
value = "Find purchase order by ID",
|
||||
nickname = "getOrderById",
|
||||
notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
|
||||
response = Order.class
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Order not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/store/order/{order_id}",
|
||||
value = "/store/order/{orderId}",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<Order> getOrderById(
|
||||
@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("order_id") Long orderId
|
||||
@Min(1L) @Max(5L) @PathVariable("orderId") Long orderId
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
@ -146,28 +108,18 @@ public interface StoreApi {
|
||||
/**
|
||||
* POST /store/order : Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet (required)
|
||||
* @param order order placed for purchasing the pet (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid Order (status code 400)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "store" },
|
||||
value = "Place an order for a pet",
|
||||
nickname = "placeOrder",
|
||||
notes = "",
|
||||
response = Order.class
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
|
||||
@ApiResponse(code = 400, message = "Invalid Order")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/store/order",
|
||||
produces = { "application/xml", "application/json" }
|
||||
produces = { "application/xml", "application/json" },
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Order> placeOrder(
|
||||
@ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody Order body
|
||||
@Valid @RequestBody Order order
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
@ -9,7 +9,7 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Controller
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/}")
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
|
||||
public class StoreApiController implements StoreApi {
|
||||
|
||||
private final NativeWebRequest request;
|
@ -8,7 +8,6 @@ package org.openapitools.api;
|
||||
import java.util.List;
|
||||
import java.time.OffsetDateTime;
|
||||
import org.openapitools.model.User;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -26,7 +25,6 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Validated
|
||||
@Api(value = "user", description = "the user API")
|
||||
public interface UserApi {
|
||||
|
||||
default Optional<NativeWebRequest> getRequest() {
|
||||
@ -37,24 +35,16 @@ public interface UserApi {
|
||||
* POST /user : Create user
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @param body Created user object (required)
|
||||
* @param user Created user object (required)
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Create user",
|
||||
nickname = "createUser",
|
||||
notes = "This can only be done by the logged in user."
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/user"
|
||||
value = "/user",
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Void> createUser(
|
||||
@ApiParam(value = "Created user object", required = true) @Valid @RequestBody User body
|
||||
@Valid @RequestBody User user
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -64,24 +54,16 @@ public interface UserApi {
|
||||
/**
|
||||
* POST /user/createWithArray : Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object (required)
|
||||
* @param user List of user object (required)
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Creates list of users with given input array",
|
||||
nickname = "createUsersWithArrayInput",
|
||||
notes = ""
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/user/createWithArray"
|
||||
value = "/user/createWithArray",
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Void> createUsersWithArrayInput(
|
||||
@ApiParam(value = "List of user object", required = true) @Valid @RequestBody List<User> body
|
||||
@Valid @RequestBody List<User> user
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -91,24 +73,16 @@ public interface UserApi {
|
||||
/**
|
||||
* POST /user/createWithList : Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object (required)
|
||||
* @param user List of user object (required)
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Creates list of users with given input array",
|
||||
nickname = "createUsersWithListInput",
|
||||
notes = ""
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/user/createWithList"
|
||||
value = "/user/createWithList",
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Void> createUsersWithListInput(
|
||||
@ApiParam(value = "List of user object", required = true) @Valid @RequestBody List<User> body
|
||||
@Valid @RequestBody List<User> user
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -123,22 +97,12 @@ public interface UserApi {
|
||||
* @return Invalid username supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Delete user",
|
||||
nickname = "deleteUser",
|
||||
notes = "This can only be done by the logged in user."
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 400, message = "Invalid username supplied"),
|
||||
@ApiResponse(code = 404, message = "User not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.DELETE,
|
||||
value = "/user/{username}"
|
||||
)
|
||||
default ResponseEntity<Void> deleteUser(
|
||||
@ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") String username
|
||||
@PathVariable("username") String username
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -153,25 +117,13 @@ public interface UserApi {
|
||||
* or Invalid username supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Get user by user name",
|
||||
nickname = "getUserByName",
|
||||
notes = "",
|
||||
response = User.class
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = User.class),
|
||||
@ApiResponse(code = 400, message = "Invalid username supplied"),
|
||||
@ApiResponse(code = 404, message = "User not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/user/{username}",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<User> getUserByName(
|
||||
@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") String username
|
||||
@PathVariable("username") String username
|
||||
) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
@ -200,25 +152,14 @@ public interface UserApi {
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid username/password supplied (status code 400)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Logs user into the system",
|
||||
nickname = "loginUser",
|
||||
notes = "",
|
||||
response = String.class
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation", response = String.class),
|
||||
@ApiResponse(code = 400, message = "Invalid username/password supplied")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/user/login",
|
||||
produces = { "application/xml", "application/json" }
|
||||
)
|
||||
default ResponseEntity<String> loginUser(
|
||||
@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) String username,
|
||||
@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) String password
|
||||
@NotNull @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) String username,
|
||||
@NotNull @Valid @RequestParam(value = "password", required = true) String password
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
@ -230,15 +171,6 @@ public interface UserApi {
|
||||
*
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Logs out current logged in user session",
|
||||
nickname = "logoutUser",
|
||||
notes = ""
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET,
|
||||
value = "/user/logout"
|
||||
@ -256,27 +188,18 @@ public interface UserApi {
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @param username name that need to be deleted (required)
|
||||
* @param body Updated user object (required)
|
||||
* @param user Updated user object (required)
|
||||
* @return Invalid user supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "user" },
|
||||
value = "Updated user",
|
||||
nickname = "updateUser",
|
||||
notes = "This can only be done by the logged in user."
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 400, message = "Invalid user supplied"),
|
||||
@ApiResponse(code = 404, message = "User not found")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.PUT,
|
||||
value = "/user/{username}"
|
||||
value = "/user/{username}",
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Void> updateUser(
|
||||
@ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") String username,
|
||||
@ApiParam(value = "Updated user object", required = true) @Valid @RequestBody User body
|
||||
@PathVariable("username") String username,
|
||||
@Valid @RequestBody User user
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
@ -9,7 +9,7 @@ import javax.annotation.Generated;
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Controller
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/}")
|
||||
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
|
||||
public class UserApiController implements UserApi {
|
||||
|
||||
private final NativeWebRequest request;
|
@ -0,0 +1,61 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
static final String API_DOCS_PATH = "/openapi.json";
|
||||
|
||||
@GetMapping(value = "/swagger-config.yaml", produces = "text/plain")
|
||||
@ResponseBody
|
||||
public String swaggerConfig() {
|
||||
return "url: " + API_DOCS_PATH + "\n";
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user