diff --git a/docs/generators/spring.md b/docs/generators/spring.md
index 43614a0a5aa0..655fa3510a3e 100644
--- a/docs/generators/spring.md
+++ b/docs/generators/spring.md
@@ -70,6 +70,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |true|
|useOptional|Use Optional container for optional parameters| |false|
|useTags|use tags for creating interface and controller classnames| |false|
+|versionToken|Token used for version type header or queryParam| |X-VERSION|
+|versionType|Add a new criteria to filter requests handled|
- **NONE**
- No filter
- **PATH**
- Filter with path prefix
- **HEADER**
- Filter with custom header
- **QUERY_PARAM**
- Filter with custom query-param
|NONE|
|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|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
index 46d4f87ea016..477e3a0b83c7 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
@@ -71,6 +71,9 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String HATEOAS = "hateoas";
public static final String RETURN_SUCCESS_CODE = "returnSuccessCode";
public static final String UNHANDLED_EXCEPTION_HANDLING = "unhandledException";
+ public static final String VERSION_TYPE = "versionType";
+ public static final String VERSION_TOKEN = "versionToken";
+ public static final String VERSION_TOKEN_DEFAULT = "X-VERSION";
public static final String OPEN_BRACE = "{";
public static final String CLOSE_BRACE = "}";
@@ -179,7 +182,13 @@ public SpringCodegen() {
CliOption library = new CliOption(CodegenConstants.LIBRARY, CodegenConstants.LIBRARY_DESC).defaultValue(SPRING_BOOT);
library.setEnum(supportedLibraries);
cliOptions.add(library);
-
+ cliOptions.add(new CliOption(VERSION_TYPE, "Add a new criteria to filter requests handled")
+ .defaultValue(VersionType.NONE.name())
+ .addEnum(VersionType.NONE.name(), "No filter")
+ .addEnum(VersionType.PATH.name(), "Filter with path prefix")
+ .addEnum(VersionType.HEADER.name(), "Filter with custom header")
+ .addEnum(VersionType.QUERY_PARAM.name(), "Filter with custom query-param"));
+ cliOptions.add(new CliOption(VERSION_TOKEN, "Token used for version type header or queryParam").defaultValue(VERSION_TOKEN_DEFAULT));
}
private void updateJava8CliOptions() {
@@ -496,6 +505,25 @@ public void processOpts() {
additionalProperties.put("lambdaTrimWhitespace", new TrimWhitespaceLambda());
additionalProperties.put("lambdaSplitString", new SplitStringLambda());
+
+ VersionType versionType = VersionType.valueOf(additionalProperties.getOrDefault(VERSION_TYPE, VersionType.NONE.name()).toString());
+ String versionToken = (String) additionalProperties.getOrDefault(VERSION_TOKEN, VERSION_TOKEN_DEFAULT);
+ switch (versionType) {
+ case PATH:
+ additionalProperties.put("versionWithPath", true);
+ break;
+ case QUERY_PARAM:
+ additionalProperties.put("versionWithQueryParam", true);
+ additionalProperties.put(VERSION_TOKEN, versionToken);
+ break;
+ case HEADER:
+ additionalProperties.put("versionWithHeader", true);
+ additionalProperties.put(VERSION_TOKEN, versionToken);
+ break;
+ case NONE:
+ default:
+ break;
+ }
}
@Override
@@ -895,4 +923,10 @@ public void postProcessParameter(CodegenParameter p) {
}
}
+ public enum VersionType {
+ NONE,
+ PATH,
+ QUERY_PARAM,
+ HEADER
+ }
}
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
index ffcfc878d83e..3db233d91b8d 100644
--- a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
@@ -62,6 +62,9 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
{{#virtualService}}
@VirtualService
{{/virtualService}}
+{{#versionWithPath}}
+@RequestMapping("/{{version}}")
+{{/versionWithPath}}
public interface {{classname}} {
{{#jdk8-default-interface}}
{{^isDelegate}}
@@ -124,6 +127,12 @@ public interface {{classname}} {
consumes = "{{{vendorExtensions.x-contentType}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}},
consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}}
+ {{#versionWithHeader}}
+ ,headers = "{{versionToken}}={{version}}"
+ {{/versionWithHeader}}
+ {{#versionWithQueryParam}}
+ ,params = "{{versionToken}}={{version}}"
+ {{/versionWithQueryParam}}
)
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},{{/-last}}{{#-last}}{{#reactive}}, {{/reactive}}{{/-last}}{{/allParams}}{{#reactive}}@ApiIgnore final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, @ApiIgnore final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}}{{#unhandledException}} throws Exception{{/unhandledException}} {
{{#delegate-method}}
diff --git a/samples/openapi3/client/petstore/python-legacy/dev-requirements.txt b/samples/openapi3/client/petstore/python-legacy/dev-requirements.txt
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/ApiResponse.md b/samples/openapi3/client/petstore/python-legacy/docs/ApiResponse.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Capitalization.md b/samples/openapi3/client/petstore/python-legacy/docs/Capitalization.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/CatAllOf.md b/samples/openapi3/client/petstore/python-legacy/docs/CatAllOf.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/ClassModel.md b/samples/openapi3/client/petstore/python-legacy/docs/ClassModel.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Client.md b/samples/openapi3/client/petstore/python-legacy/docs/Client.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/DogAllOf.md b/samples/openapi3/client/petstore/python-legacy/docs/DogAllOf.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/File.md b/samples/openapi3/client/petstore/python-legacy/docs/File.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/python-legacy/docs/HasOnlyReadOnly.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/InlineObject.md b/samples/openapi3/client/petstore/python-legacy/docs/InlineObject.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/InlineObject4.md b/samples/openapi3/client/petstore/python-legacy/docs/InlineObject4.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/InlineResponseDefault.md b/samples/openapi3/client/petstore/python-legacy/docs/InlineResponseDefault.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/List.md b/samples/openapi3/client/petstore/python-legacy/docs/List.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Model200Response.md b/samples/openapi3/client/petstore/python-legacy/docs/Model200Response.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/ModelReturn.md b/samples/openapi3/client/petstore/python-legacy/docs/ModelReturn.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Name.md b/samples/openapi3/client/petstore/python-legacy/docs/Name.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/NumberOnly.md b/samples/openapi3/client/petstore/python-legacy/docs/NumberOnly.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/OuterComposite.md b/samples/openapi3/client/petstore/python-legacy/docs/OuterComposite.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/OuterEnum.md b/samples/openapi3/client/petstore/python-legacy/docs/OuterEnum.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumDefaultValue.md b/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumDefaultValue.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumInteger.md b/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumInteger.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumIntegerDefaultValue.md b/samples/openapi3/client/petstore/python-legacy/docs/OuterEnumIntegerDefaultValue.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/python-legacy/docs/ReadOnlyFirst.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/docs/SpecialModelName.md b/samples/openapi3/client/petstore/python-legacy/docs/SpecialModelName.md
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/setup.cfg b/samples/openapi3/client/petstore/python-legacy/setup.cfg
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/test_python2.sh b/samples/openapi3/client/petstore/python-legacy/test_python2.sh
old mode 100755
new mode 100644
diff --git a/samples/openapi3/client/petstore/python-legacy/test_python2_and_3.sh b/samples/openapi3/client/petstore/python-legacy/test_python2_and_3.sh
old mode 100755
new mode 100644