Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,6 @@ public void processOpts() {
documentationProvider = DocumentationProvider.NONE;
annotationLibrary = AnnotationLibrary.NONE;
useJakartaEe = true;
useBeanValidation = false;
performBeanValidation = false;

additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);
additionalProperties.put(USE_BEANVALIDATION, useBeanValidation);
Expand All @@ -443,7 +441,7 @@ public void processOpts() {

applyJakartaPackage();

LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary, useBeanValidation, performBeanValidation. "
LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary. "
+ "useJakartaEe defaulted to 'true'");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6664,4 +6664,42 @@ public void testJspecify(String library, int springBootVersion, String fooApiFil
JavaFileAssert.assertThat(files.get("model/package-info.java"))
.fileContains("@org.jspecify.annotations.NullMarked");
}

@Test
public void useBeanValidationTrueWithSpringHttpInterface() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/petstore.yaml", null, new ParseOptions())
.getOpenAPI();

SpringCodegen codegen = new SpringCodegen();
codegen.setLibrary(SPRING_HTTP_INTERFACE);
codegen.setOutputDir(output.getAbsolutePath());
codegen.setUseBeanValidation(true);
codegen.setPerformBeanValidation(true);
codegen.setUseSpringBoot3(true);

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();
generator.setGenerateMetadata(false);
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");

generator.opts(input).generate();

Path pet = Paths.get(
output.getAbsolutePath(),
"src/main/java/org/openapitools/model/Pet.java"
);

String content = Files.readString(pet);

assertThat(content).contains("@NotNull");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void createUser(
contentType = "application/json"
)
void createUsersWithArrayInput(
@RequestBody List<UserDto> userDto
@RequestBody List<@Valid UserDto> userDto
);


Expand All @@ -74,7 +74,7 @@ void createUsersWithArrayInput(
contentType = "application/json"
)
void createUsersWithListInput(
@RequestBody List<UserDto> userDto
@RequestBody List<@Valid UserDto> userDto
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayTestDto {
private List<List<Long>> arrayArrayOfInteger = new ArrayList<>();


private List<List<ReadOnlyFirstDto>> arrayArrayOfModel = new ArrayList<>();
private List<List<@Valid ReadOnlyFirstDto>> arrayArrayOfModel = new ArrayList<>();

public ArrayTestDto arrayOfString(List<String> arrayOfString) {
this.arrayOfString = arrayOfString;
Expand Down Expand Up @@ -91,12 +91,12 @@ public void setArrayArrayOfInteger(List<List<Long>> arrayArrayOfInteger) {
this.arrayArrayOfInteger = arrayArrayOfInteger;
}

public ArrayTestDto arrayArrayOfModel(List<List<ReadOnlyFirstDto>> arrayArrayOfModel) {
public ArrayTestDto arrayArrayOfModel(List<List<@Valid ReadOnlyFirstDto>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
return this;
}

public ArrayTestDto addArrayArrayOfModelItem(List<ReadOnlyFirstDto> arrayArrayOfModelItem) {
public ArrayTestDto addArrayArrayOfModelItem(List<@Valid ReadOnlyFirstDto> arrayArrayOfModelItem) {
if (this.arrayArrayOfModel == null) {
this.arrayArrayOfModel = new ArrayList<>();
}
Expand All @@ -110,12 +110,12 @@ public ArrayTestDto addArrayArrayOfModelItem(List<ReadOnlyFirstDto> arrayArrayOf
*/

@JsonProperty("array_array_of_model")
public List<List<ReadOnlyFirstDto>> getArrayArrayOfModel() {
public List<List<@Valid ReadOnlyFirstDto>> getArrayArrayOfModel() {
return arrayArrayOfModel;
}

@JsonProperty("array_array_of_model")
public void setArrayArrayOfModel(List<List<ReadOnlyFirstDto>> arrayArrayOfModel) {
public void setArrayArrayOfModel(List<List<@Valid ReadOnlyFirstDto>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FileSchemaTestClassDto {
private @Nullable FileDto file;


private List<FileDto> files = new ArrayList<>();
private List<@Valid FileDto> files = new ArrayList<>();

public FileSchemaTestClassDto file(@Nullable FileDto file) {
this.file = file;
Expand All @@ -51,7 +51,7 @@ public void setFile(@Nullable FileDto file) {
this.file = file;
}

public FileSchemaTestClassDto files(List<FileDto> files) {
public FileSchemaTestClassDto files(List<@Valid FileDto> files) {
this.files = files;
return this;
}
Expand All @@ -70,12 +70,12 @@ public FileSchemaTestClassDto addFilesItem(FileDto filesItem) {
*/

@JsonProperty("files")
public List<FileDto> getFiles() {
public List<@Valid FileDto> getFiles() {
return files;
}

@JsonProperty("files")
public void setFiles(List<FileDto> files) {
public void setFiles(List<@Valid FileDto> files) {
this.files = files;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PetDto {
private Set<String> photoUrls = new LinkedHashSet<>();


private List<TagDto> tags = new ArrayList<>();
private List<@Valid TagDto> tags = new ArrayList<>();

/**
* pet status in the store
Expand Down Expand Up @@ -176,7 +176,7 @@ public void setPhotoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
}

public PetDto tags(List<TagDto> tags) {
public PetDto tags(List<@Valid TagDto> tags) {
this.tags = tags;
return this;
}
Expand All @@ -195,12 +195,12 @@ public PetDto addTagsItem(TagDto tagsItem) {
*/

@JsonProperty("tags")
public List<TagDto> getTags() {
public List<@Valid TagDto> getTags() {
return tags;
}

@JsonProperty("tags")
public void setTags(List<TagDto> tags) {
public void setTags(List<@Valid TagDto> tags) {
this.tags = tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ArrayTest {
private List<List<Long>> arrayArrayOfInteger = new ArrayList<>();


private List<List<ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();
private List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();

public ArrayTest arrayOfString(List<String> arrayOfString) {
this.arrayOfString = arrayOfString;
Expand Down Expand Up @@ -89,12 +89,12 @@ public void setArrayArrayOfInteger(List<List<Long>> arrayArrayOfInteger) {
this.arrayArrayOfInteger = arrayArrayOfInteger;
}

public ArrayTest arrayArrayOfModel(List<List<ReadOnlyFirst>> arrayArrayOfModel) {
public ArrayTest arrayArrayOfModel(List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
return this;
}

public ArrayTest addArrayArrayOfModelItem(List<ReadOnlyFirst> arrayArrayOfModelItem) {
public ArrayTest addArrayArrayOfModelItem(List<@Valid ReadOnlyFirst> arrayArrayOfModelItem) {
if (this.arrayArrayOfModel == null) {
this.arrayArrayOfModel = new ArrayList<>();
}
Expand All @@ -108,12 +108,12 @@ public ArrayTest addArrayArrayOfModelItem(List<ReadOnlyFirst> arrayArrayOfModelI
*/

@JsonProperty("array_array_of_model")
public List<List<ReadOnlyFirst>> getArrayArrayOfModel() {
public List<List<@Valid ReadOnlyFirst>> getArrayArrayOfModel() {
return arrayArrayOfModel;
}

@JsonProperty("array_array_of_model")
public void setArrayArrayOfModel(List<List<ReadOnlyFirst>> arrayArrayOfModel) {
public void setArrayArrayOfModel(List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FileSchemaTestClass {
private @Nullable File file;


private List<File> files = new ArrayList<>();
private List<@Valid File> files = new ArrayList<>();

public FileSchemaTestClass file(@Nullable File file) {
this.file = file;
Expand All @@ -49,7 +49,7 @@ public void setFile(@Nullable File file) {
this.file = file;
}

public FileSchemaTestClass files(List<File> files) {
public FileSchemaTestClass files(List<@Valid File> files) {
this.files = files;
return this;
}
Expand All @@ -68,12 +68,12 @@ public FileSchemaTestClass addFilesItem(File filesItem) {
*/

@JsonProperty("files")
public List<File> getFiles() {
public List<@Valid File> getFiles() {
return files;
}

@JsonProperty("files")
public void setFiles(List<File> files) {
public void setFiles(List<@Valid File> files) {
this.files = files;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Pet {
private Set<String> photoUrls = new LinkedHashSet<>();


private List<Tag> tags = new ArrayList<>();
private List<@Valid Tag> tags = new ArrayList<>();

/**
* pet status in the store
Expand Down Expand Up @@ -182,7 +182,7 @@ public void setPhotoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
}

public Pet tags(List<Tag> tags) {
public Pet tags(List<@Valid Tag> tags) {
this.tags = tags;
return this;
}
Expand All @@ -201,12 +201,12 @@ public Pet addTagsItem(Tag tagsItem) {
*/

@JsonProperty("tags")
public List<Tag> getTags() {
public List<@Valid Tag> getTags() {
return tags;
}

@JsonProperty("tags")
public void setTags(List<Tag> tags) {
public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ArrayTest {
private List<List<Long>> arrayArrayOfInteger = new ArrayList<>();


private List<List<ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();
private List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();

public ArrayTest arrayOfString(List<String> arrayOfString) {
this.arrayOfString = arrayOfString;
Expand Down Expand Up @@ -89,12 +89,12 @@ public void setArrayArrayOfInteger(List<List<Long>> arrayArrayOfInteger) {
this.arrayArrayOfInteger = arrayArrayOfInteger;
}

public ArrayTest arrayArrayOfModel(List<List<ReadOnlyFirst>> arrayArrayOfModel) {
public ArrayTest arrayArrayOfModel(List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
return this;
}

public ArrayTest addArrayArrayOfModelItem(List<ReadOnlyFirst> arrayArrayOfModelItem) {
public ArrayTest addArrayArrayOfModelItem(List<@Valid ReadOnlyFirst> arrayArrayOfModelItem) {
if (this.arrayArrayOfModel == null) {
this.arrayArrayOfModel = new ArrayList<>();
}
Expand All @@ -108,12 +108,12 @@ public ArrayTest addArrayArrayOfModelItem(List<ReadOnlyFirst> arrayArrayOfModelI
*/

@JsonProperty("array_array_of_model")
public List<List<ReadOnlyFirst>> getArrayArrayOfModel() {
public List<List<@Valid ReadOnlyFirst>> getArrayArrayOfModel() {
return arrayArrayOfModel;
}

@JsonProperty("array_array_of_model")
public void setArrayArrayOfModel(List<List<ReadOnlyFirst>> arrayArrayOfModel) {
public void setArrayArrayOfModel(List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel) {
this.arrayArrayOfModel = arrayArrayOfModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FileSchemaTestClass {
private @Nullable File file;


private List<File> files = new ArrayList<>();
private List<@Valid File> files = new ArrayList<>();

public FileSchemaTestClass file(@Nullable File file) {
this.file = file;
Expand All @@ -49,7 +49,7 @@ public void setFile(@Nullable File file) {
this.file = file;
}

public FileSchemaTestClass files(List<File> files) {
public FileSchemaTestClass files(List<@Valid File> files) {
this.files = files;
return this;
}
Expand All @@ -68,12 +68,12 @@ public FileSchemaTestClass addFilesItem(File filesItem) {
*/

@JsonProperty("files")
public List<File> getFiles() {
public List<@Valid File> getFiles() {
return files;
}

@JsonProperty("files")
public void setFiles(List<File> files) {
public void setFiles(List<@Valid File> files) {
this.files = files;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Pet {
private Set<String> photoUrls = new LinkedHashSet<>();


private List<Tag> tags = new ArrayList<>();
private List<@Valid Tag> tags = new ArrayList<>();

/**
* pet status in the store
Expand Down Expand Up @@ -182,7 +182,7 @@ public void setPhotoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
}

public Pet tags(List<Tag> tags) {
public Pet tags(List<@Valid Tag> tags) {
this.tags = tags;
return this;
}
Expand All @@ -201,12 +201,12 @@ public Pet addTagsItem(Tag tagsItem) {
*/

@JsonProperty("tags")
public List<Tag> getTags() {
public List<@Valid Tag> getTags() {
return tags;
}

@JsonProperty("tags")
public void setTags(List<Tag> tags) {
public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

Expand Down
Loading
Loading