Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the FQCN to the @Size-annotation. #975

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -2,6 +2,7 @@

import java.io.File;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -16,6 +17,8 @@
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.languages.JavaClientCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.ProcessUtils;
import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -43,6 +46,31 @@ public QuarkusJavaClientCodegen() {
this.setTemplateDir("templates");
}

@Override
public ModelsMap postProcessModels(ModelsMap objs) {
objs = super.postProcessModels(objs);

objs.getModels().stream()
.map(ModelMap::getModel)
.map(CodegenModel::getVars)
.flatMap(Collection::stream)
.filter(codegenProperty -> codegenProperty.getDatatypeWithEnum().contains("@Size")
|| codegenProperty.getDataType().contains("@Size"))
.forEach(modelMap -> {
Optional.of(modelMap)
.map(CodegenProperty::getDatatypeWithEnum)
.map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size"))
.ifPresent(modelMap::setDatatypeWithEnum);

Optional.of(modelMap)
.map(CodegenProperty::getDataType)
.map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size"))
.ifPresent(modelMap::setDataType);
});

return objs;
}

@Override
public String getName() {
return "quarkus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ components:
- name
- secondName
- size
- listOfStrings
properties:
id:
type: integer
Expand All @@ -64,4 +65,9 @@ components:
size:
type: number
minimum: 1.0
maximum: 10.0
maximum: 10.0
listOfStrings:
type: array
items:
type: string
minLength: 1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception {
Field name = ValidatedObject.class.getDeclaredField("name");
Field secondName = ValidatedObject.class.getDeclaredField("secondName");
Field size = ValidatedObject.class.getDeclaredField("size");
Field listOfStrings = ValidatedObject.class.getDeclaredField("listOfStrings");

assertThat(Stream.of(id, name, secondName, size)
.allMatch(f -> f.isAnnotationPresent(NotNull.class)))
Expand All @@ -69,6 +70,9 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception {
assertThat(size.getAnnotation(DecimalMin.class).value()).isEqualTo("1.0");
assertThat(size.isAnnotationPresent(DecimalMax.class)).isTrue();
assertThat(size.getAnnotation(DecimalMax.class).value()).isEqualTo("10.0");

assertThat(listOfStrings.isAnnotationPresent(NotNull.class)).isTrue();
assertThat(listOfStrings.isAnnotationPresent(Valid.class)).isTrue();
}

@Test
Expand Down