Skip to content

Commit bf93e8e

Browse files
committed
add option additionalNotNullAnnotations
1 parent 536016b commit bf93e8e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class SpringCodegen extends AbstractJavaCodegen
108108
public static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
109109
public static final String JACKSON3_PACKAGE = "tools.jackson";
110110
public static final String JACKSON_PACKAGE = "jacksonPackage";
111+
public static final String ADDITIONAL_NOT_NULL_ANNOTATIONS = "additionalNotNullAnnotations";
111112

112113
@Getter
113114
public enum RequestMappingMode {
@@ -180,6 +181,8 @@ public enum RequestMappingMode {
180181
protected boolean useDeductionForOneOfInterfaces = false;
181182
@Getter @Setter
182183
protected boolean useJackson3 = false;
184+
@Getter @Setter
185+
protected boolean additionalNotNullAnnotations = false;
183186

184187
public SpringCodegen() {
185188
super();
@@ -269,7 +272,6 @@ public SpringCodegen() {
269272
cliOptions.add(CliOption.newString(X_IMPLEMENTS_SKIP, "Ability to choose interfaces that should NOT be implemented in the models despite their presence in vendor extension `x-implements`. Takes a list of fully qualified interface names. Example: yaml `xImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface `com.some.pack.WithPhotoUrls` in any schema", "empty list"));
270273
cliOptions.add(CliOption.newString(SCHEMA_IMPLEMENTS, "Ability to supply interfaces per schema that should be implemented (serves similar purpose as vendor extension `x-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map"));
271274

272-
273275
CliOption requestMappingOpt = new CliOption(REQUEST_MAPPING_OPTION,
274276
"Where to generate the class level @RequestMapping annotation.")
275277
.defaultValue(requestMappingMode.name());
@@ -325,6 +327,10 @@ public SpringCodegen() {
325327
library.setEnum(supportedLibraries);
326328
cliOptions.add(library);
327329

330+
cliOptions.add(CliOption.newBoolean(ADDITIONAL_NOT_NULL_ANNOTATIONS,
331+
"Add @NotNull to path variables (required by default) and requestBody.",
332+
additionalNotNullAnnotations));
333+
328334
}
329335

330336
@Override
@@ -532,6 +538,7 @@ public void processOpts() {
532538
}
533539
convertPropertyToStringAndWriteBack(RESOURCE_FOLDER, this::setResourceFolder);
534540

541+
convertPropertyToBooleanAndWriteBack(ADDITIONAL_NOT_NULL_ANNOTATIONS, this::setAdditionalNotNullAnnotations);
535542

536543
// override parent one
537544
importMapping.put("JsonDeserialize", (useJackson3 ? JACKSON3_PACKAGE : JACKSON2_PACKAGE) + ".databind.annotation.JsonDeserialize");

0 commit comments

Comments
 (0)