forked from loafle/openapi-generator-original
Added space between @NotNull-annotation and Java type to produce code that can be compiled. fix #11340 (#12034)
This commit is contained in:
parent
224a082906
commit
c21d2cde19
@ -1 +1 @@
|
||||
{{#required}} @NotNull{{/required}}{{>beanValidationCore}}
|
||||
{{#required}} @NotNull {{/required}}{{>beanValidationCore}}
|
@ -37,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -53,8 +54,10 @@ import org.openapitools.codegen.CodegenSecurity;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.openapitools.codegen.languages.AbstractJavaCodegen;
|
||||
import org.openapitools.codegen.languages.JavaClientCodegen;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Ignore;
|
||||
@ -1409,4 +1412,36 @@ public class JavaClientCodegenTest {
|
||||
TestUtils.assertExtraAnnotationFiles(outputPath + "/src/main/java/org/openapitools/client/model");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://github.com/OpenAPITools/openapi-generator/issues/11340
|
||||
*/
|
||||
@Test
|
||||
public void testReferencedHeader2() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put(BeanValidationFeatures.USE_BEANVALIDATION, "true");
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("java")
|
||||
.setAdditionalProperties(additionalProperties)
|
||||
.setInputSpec("src/test/resources/3_0/issue-11340.yaml")
|
||||
.setOutputDir(output.getAbsolutePath()
|
||||
.replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
|
||||
Map<String, File> files = generator.opts(clientOptInput).generate().stream()
|
||||
.collect(Collectors.toMap(File::getName, Function.identity()));
|
||||
|
||||
JavaFileAssert.assertThat(files.get("DefaultApi.java"))
|
||||
.assertMethod("operationWithHttpInfo")
|
||||
.hasParameter("requestBody")
|
||||
.assertParameterAnnotations()
|
||||
.containsWithName("NotNull")
|
||||
.toParameter().toMethod()
|
||||
.hasParameter("xNonNullHeaderParameter")
|
||||
.assertParameterAnnotations()
|
||||
.containsWithName("NotNull");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
openapi: "3.0.3"
|
||||
info:
|
||||
title: Issue 11340 - Bean Validation Breaks Generated Java Code
|
||||
version: "1.0.2"
|
||||
description: With Bean Validation @NotNull and type of parameter must be separated by space.
|
||||
paths:
|
||||
/configuration:
|
||||
put:
|
||||
operationId: operation
|
||||
description: Operation with required header and required request body
|
||||
parameters:
|
||||
- in: header
|
||||
name: x-non-null-header-parameter
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
minProperties: 1
|
||||
additionalProperties:
|
||||
type: object
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
Loading…
x
Reference in New Issue
Block a user