forked from loafle/openapi-generator-original
Fix #17752 - Add dependency for jakarta-validation-api and hibernate-validator to pom.xml file for Java client with Resttemplate library (#17753)
Co-authored-by: NC90131N <nathanael-externe.couret@enedis.fr>
This commit is contained in:
@@ -313,6 +313,23 @@
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/useBeanValidation}}
|
||||
{{#performBeanValidation}}
|
||||
<!-- Bean Validation Impl. used to perform BeanValidation -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate-validator-version}</version>
|
||||
</dependency>
|
||||
{{/performBeanValidation}}
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
@@ -356,6 +373,12 @@
|
||||
{{#joda}}
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
{{/joda}}
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>2.0.2</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
{{#performBeanValidation}}
|
||||
<hibernate-validator-version>5.4.3.Final</hibernate-validator-version>
|
||||
{{/performBeanValidation}}
|
||||
<junit-version>4.13.2</junit-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -2643,6 +2643,129 @@ public class JavaClientCodegenTest {
|
||||
TestUtils.assertFileContains(petApi, "@Component");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestTemplateWithUseBeanValidationEnabled() throws IOException {
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
properties.put(JavaClientCodegen.USE_BEANVALIDATION, true);
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/petstore.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
Path pomFile = Paths.get(output + "/pom.xml");
|
||||
TestUtils.assertFileContains(pomFile, "<artifactId>jakarta.validation-api</artifactId>");
|
||||
|
||||
Path petModel = Paths.get(output + "/src/main/java/org/openapitools/client/model/Pet.java");
|
||||
TestUtils.assertFileContains(petModel, "@Valid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestTemplateWithUseBeanValidationDisabled() throws IOException {
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
properties.put(JavaClientCodegen.USE_BEANVALIDATION, false);
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/petstore.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
Path pomFile = Paths.get(output + "/pom.xml");
|
||||
TestUtils.assertFileNotContains(pomFile, "<artifactId>jakarta.validation-api</artifactId>");
|
||||
|
||||
Path petModel = Paths.get(output + "/src/main/java/org/openapitools/client/model/Pet.java");
|
||||
TestUtils.assertFileNotContains(petModel, "@Valid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestTemplateWithPerformBeanValidationEnabled() throws IOException {
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
properties.put(JavaClientCodegen.PERFORM_BEANVALIDATION, true);
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/petstore.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
Path pomFile = Paths.get(output + "/pom.xml");
|
||||
TestUtils.assertFileContains(pomFile, "<artifactId>hibernate-validator</artifactId>");
|
||||
|
||||
Path petApi = Paths.get(output + "/src/main/java/xyz/abcdef/BeanValidationException.java");
|
||||
TestUtils.assertFileExists(petApi);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestTemplateWithPerformBeanValidationDisabled() throws IOException {
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
properties.put(JavaClientCodegen.PERFORM_BEANVALIDATION, false);
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/petstore.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
Path pomFile = Paths.get(output + "/pom.xml");
|
||||
TestUtils.assertFileNotContains(pomFile, "<artifactId>hibernate-validator</artifactId>");
|
||||
|
||||
Path petApi = Paths.get(output + "/src/main/java/org/openapitools/client/invoker/BeanValidationException.java");
|
||||
TestUtils.assertFileNotExists(petApi);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLogicToAvoidStackOverflow() throws IOException {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user