Skip to content

Commit 249d796

Browse files
Add a unit test to show that the annotations are generated as expected
1 parent c9d0505 commit 249d796

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,40 @@ public void testHasOperationParameterExtraAnnotation_issue18224() throws IOExcep
34903490
.containsWithName("com.test.MyAnnotationInHeader");
34913491
}
34923492

3493+
@Test
3494+
public void testModelHasParameterExtraAnnotations_issue19953() {
3495+
Path output = TestUtils.newTempFolder();
3496+
3497+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_18224.yaml");
3498+
final SpringCodegen codegen = new SpringCodegen();
3499+
codegen.setOpenAPI(openAPI);
3500+
codegen.setOutputDir(output.toString());
3501+
3502+
codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8-localdatetime");
3503+
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
3504+
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, "false");
3505+
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
3506+
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");
3507+
codegen.additionalProperties().put(SPRING_CONTROLLER, "true");
3508+
3509+
ClientOptInput input = new ClientOptInput();
3510+
input.openAPI(openAPI);
3511+
input.config(codegen);
3512+
3513+
DefaultGenerator generator = new DefaultGenerator();
3514+
generator.setGenerateMetadata(false); // skip metadata generation
3515+
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
3516+
3517+
Map<String, File> files = generator.opts(input).generate().stream()
3518+
.collect(Collectors.toMap(File::getName, Function.identity()));
3519+
3520+
JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("ObjTest.java"));
3521+
javaFileAssert.assertProperty("field3")
3522+
.assertPropertyAnnotations()
3523+
.containsWithName("com.test.MyAnnotation")
3524+
.containsWithName("com.test.MyAnnotation2");
3525+
}
3526+
34933527
@Test
34943528
public void testHasOperationExtraAnnotation_issue15822() throws IOException {
34953529
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();

modules/openapi-generator/src/test/resources/3_0/issue_18224.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ components:
6464
field3:
6565
type: string
6666
pattern: "\\w"
67+
x-field-extra-annotation:
68+
- '@com.test.MyAnnotation'
69+
- '@com.test.MyAnnotation2'

0 commit comments

Comments
 (0)