Skip to content

Commit 66a6693

Browse files
committed
Merge changes from martin-mfg
Merge master
1 parent 3119eca commit 66a6693

26 files changed

Lines changed: 87 additions & 29 deletions

File tree

docs/generators/protobuf-schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2121
|addJsonNameAnnotation|Append "json_name" annotation to message field when the specification name differs from the protobuf field name| |false|
2222
|numberedFieldNumberList|Field numbers in order.| |false|
2323
|startEnumsWithUnspecified|Introduces "UNSPECIFIED" as the first element of enumerations.| |false|
24+
|wrapComplexType|Generate Additional message for complex type| |true|
2425

2526
## IMPORT MAPPING
2627

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class SpringCodegen extends AbstractJavaCodegen
6666
public static final String INTERFACE_ONLY = "interfaceOnly";
6767
public static final String USE_FEIGN_CLIENT_URL = "useFeignClientUrl";
6868
public static final String USE_FEIGN_CLIENT = "useFeignClient";
69+
public static final String USE_FEIGN_CLIENT_CONTEXT_ID = "useFeignClientContextId";
6970
public static final String DELEGATE_PATTERN = "delegatePattern";
7071
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
7172
public static final String VIRTUAL_SERVICE = "virtualService";
@@ -96,6 +97,7 @@ public class SpringCodegen extends AbstractJavaCodegen
9697
public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface";
9798
public static final String USE_SEALED = "useSealed";
9899
public static final String OPTIONAL_ACCEPT_NULLABLE = "optionalAcceptNullable";
100+
public static final String USE_SPRING_BUILT_IN_VALIDATION = "useSpringBuiltInValidation";
99101
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";
100102

101103
@Getter
@@ -124,6 +126,7 @@ public enum RequestMappingMode {
124126

125127
@Setter protected boolean interfaceOnly = false;
126128
@Setter protected boolean useFeignClientUrl = true;
129+
@Setter protected boolean useFeignClientContextId = true;
127130
@Setter protected boolean delegatePattern = false;
128131
protected boolean delegateMethod = false;
129132
@Setter protected boolean singleContentTypes = false;
@@ -154,6 +157,8 @@ public enum RequestMappingMode {
154157
@Getter @Setter
155158
protected boolean optionalAcceptNullable = true;
156159
@Getter @Setter
160+
protected boolean useSpringBuiltInValidation = false;
161+
@Getter @Setter
157162
protected boolean useDeductionForOneOfInterfaces = false;
158163

159164
public SpringCodegen() {
@@ -200,6 +205,8 @@ public SpringCodegen() {
200205
"Whether to generate only API interface stubs without the server files.", interfaceOnly));
201206
cliOptions.add(CliOption.newBoolean(USE_FEIGN_CLIENT_URL,
202207
"Whether to generate Feign client with url parameter.", useFeignClientUrl));
208+
cliOptions.add(CliOption.newBoolean(USE_FEIGN_CLIENT_CONTEXT_ID,
209+
"Whether to generate Feign client with contextId parameter.", useFeignClientContextId));
203210
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN,
204211
"Whether to generate the server files using the delegate pattern", delegatePattern));
205212
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES,
@@ -217,6 +224,9 @@ public SpringCodegen() {
217224
CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames", useTags));
218225
cliOptions
219226
.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation));
227+
cliOptions.add(CliOption.newBoolean(USE_SPRING_BUILT_IN_VALIDATION,
228+
"Disable `@Validated` at the class level when using built-in validation.",
229+
useSpringBuiltInValidation));
220230
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION,
221231
"Use Bean Validation Impl. to perform BeanValidation", performBeanValidation));
222232
cliOptions.add(CliOption.newBoolean(USE_SEALED,
@@ -396,6 +406,7 @@ public void processOpts() {
396406
convertPropertyToBooleanAndWriteBack(VIRTUAL_SERVICE, this::setVirtualService);
397407
convertPropertyToBooleanAndWriteBack(INTERFACE_ONLY, this::setInterfaceOnly);
398408
convertPropertyToBooleanAndWriteBack(USE_FEIGN_CLIENT_URL, this::setUseFeignClientUrl);
409+
convertPropertyToBooleanAndWriteBack(USE_FEIGN_CLIENT_CONTEXT_ID, this::setUseFeignClientContextId);
399410
convertPropertyToBooleanAndWriteBack(DELEGATE_PATTERN, this::setDelegatePattern);
400411
convertPropertyToBooleanAndWriteBack(SINGLE_CONTENT_TYPES, this::setSingleContentTypes);
401412
convertPropertyToBooleanAndWriteBack(SKIP_DEFAULT_INTERFACE, this::setSkipDefaultInterface);
@@ -427,6 +438,7 @@ public void processOpts() {
427438
convertPropertyToBooleanAndWriteBack(UNHANDLED_EXCEPTION_HANDLING, this::setUnhandledException);
428439
convertPropertyToBooleanAndWriteBack(USE_RESPONSE_ENTITY, this::setUseResponseEntity);
429440
convertPropertyToBooleanAndWriteBack(OPTIONAL_ACCEPT_NULLABLE, this::setOptionalAcceptNullable);
441+
convertPropertyToBooleanAndWriteBack(USE_SPRING_BUILT_IN_VALIDATION, this::setUseSpringBuiltInValidation);
430442
convertPropertyToBooleanAndWriteBack(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, this::setUseDeductionForOneOfInterfaces);
431443

432444
additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda());

modules/openapi-generator/src/main/resources/JavaSpring/api.mustache

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ import org.springframework.http.HttpStatus;
3737
{{#useResponseEntity}}
3838
import org.springframework.http.ResponseEntity;
3939
{{/useResponseEntity}}
40-
{{#useBeanValidation}}
41-
import org.springframework.validation.annotation.Validated;
42-
{{/useBeanValidation}}
40+
{{#useBeanValidation}}{{^useSpringBuiltInValidation}}import org.springframework.validation.annotation.Validated;{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
4341
{{#useSpringController}}
4442
{{#useResponseEntity}}
4543
import org.springframework.stereotype.Controller;
@@ -82,9 +80,7 @@ import java.util.concurrent.CompletableFuture;
8280
import {{javaxPackage}}.annotation.Generated;
8381

8482
{{>generatedAnnotation}}
85-
{{#useBeanValidation}}
86-
@Validated
87-
{{/useBeanValidation}}
83+
{{#useBeanValidation}}{{^useSpringBuiltInValidation}}@Validated{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
8884
{{#useSpringController}}
8985
{{#useResponseEntity}}
9086
@Controller

modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/apiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package {{package}};
33
import org.springframework.cloud.openfeign.FeignClient;
44
import {{configPackage}}.ClientConfiguration;
55

6-
@FeignClient(name="${{openbrace}}{{classVarName}}.name:{{classVarName}}{{closebrace}}", {{#useFeignClientUrl}}url="${{openbrace}}{{classVarName}}.url:{{basePath}}{{closebrace}}", {{/useFeignClientUrl}}configuration = ClientConfiguration.class)
6+
@FeignClient(name="${{openbrace}}{{classVarName}}.name:{{classVarName}}{{closebrace}}", {{#useFeignClientContextId}}contextId="${{openbrace}}{{classVarName}}.contextId:${{openbrace}}{{classVarName}}.name{{closebrace}}{{closebrace}}",{{/useFeignClientContextId}} {{#useFeignClientUrl}}url="${{openbrace}}{{classVarName}}.url:{{basePath}}{{closebrace}}",{{/useFeignClientUrl}} configuration = ClientConfiguration.class)
77
public interface {{classname}}Client extends {{classname}} {
88
}

modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* @deprecated{{/isDeprecated}}
44
*/
55
{{>additionalModelTypeAnnotations}}
6-
{{#description}}
76
{{#isDeprecated}}
87
@Deprecated
98
{{/isDeprecated}}
9+
{{#description}}
1010
{{#swagger1AnnotationLibrary}}
1111
@ApiModel(description = "{{{description}}}")
1212
{{/swagger1AnnotationLibrary}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.12.0
1+
sbt.version=1.10.11

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5385,4 +5385,53 @@ public void testEnumWithImplements() {
53855385

53865386
JavaFileAssert.assertThat(files.get("Type.java")).fileContains("Type implements java.io.Serializable {");
53875387
}
5388-
}
5388+
@Test
5389+
public void shouldEnableBuiltInValidationOptionWhenSetToTrue() throws IOException {
5390+
final SpringCodegen codegen = new SpringCodegen();
5391+
codegen.setUseSpringBoot3(true);
5392+
codegen.setUseOptional(true);
5393+
codegen.additionalProperties().put(SpringCodegen.USE_BEANVALIDATION, true);
5394+
codegen.additionalProperties().put(SpringCodegen.USE_SPRING_BUILT_IN_VALIDATION, true);
5395+
5396+
Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/petstore.yaml");
5397+
var file = files.get("UserApi.java");
5398+
5399+
JavaFileAssert.assertThat(file)
5400+
.hasNoImports("org.springframework.validation.annotation.Validated")
5401+
.assertTypeAnnotations()
5402+
.doesNotContainWithName("Validated");
5403+
}
5404+
5405+
@Test
5406+
public void shouldDisableBuiltInValidationOptionWhenSetToFalse() throws IOException {
5407+
final SpringCodegen codegen = new SpringCodegen();
5408+
codegen.setUseSpringBoot3(true);
5409+
codegen.setUseOptional(true);
5410+
codegen.additionalProperties().put(SpringCodegen.USE_BEANVALIDATION, true);
5411+
codegen.additionalProperties().put(SpringCodegen.USE_SPRING_BUILT_IN_VALIDATION, false);
5412+
5413+
Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/petstore.yaml");
5414+
var file = files.get("UserApi.java");
5415+
5416+
JavaFileAssert.assertThat(file)
5417+
.hasImports("org.springframework.validation.annotation.Validated")
5418+
.assertTypeAnnotations()
5419+
.containsWithName("Validated");
5420+
}
5421+
5422+
@Test
5423+
public void shouldDisableBuiltInValidationOptionByDefault() throws IOException {
5424+
final SpringCodegen codegen = new SpringCodegen();
5425+
codegen.setUseSpringBoot3(true);
5426+
codegen.setUseOptional(true);
5427+
codegen.additionalProperties().put(SpringCodegen.USE_BEANVALIDATION, true);
5428+
5429+
Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/petstore.yaml");
5430+
var file = files.get("UserApi.java");
5431+
5432+
JavaFileAssert.assertThat(file)
5433+
.hasImports("org.springframework.validation.annotation.Validated")
5434+
.assertTypeAnnotations()
5435+
.containsWithName("Validated");
5436+
}
5437+
}

samples/client/petstore/spring-cloud-auth/src/main/java/org/openapitools/api/SomeApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${some.name:some}", url="${some.url:http://localhost}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${some.name:some}", contextId="${some.contextId:${some.name}}", url="${some.url:http://localhost}", configuration = ClientConfiguration.class)
77
public interface SomeApiClient extends SomeApi {
88
}

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/api/PetApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/api/StoreApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

0 commit comments

Comments
 (0)