Skip to content

Commit 3e0a9f7

Browse files
authored
fix spring-http-interface created swagger annotations (#23073)
1 parent 276d690 commit 3e0a9f7

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ public void processOpts() {
414414
super.processOpts();
415415

416416
if (SPRING_HTTP_INTERFACE.equals(library)) {
417+
if (documentationProvider != null) {
418+
additionalProperties.remove(documentationProvider.getPropertyName());
419+
}
420+
if (annotationLibrary != null) {
421+
additionalProperties.remove(annotationLibrary.getPropertyName());
422+
}
417423
documentationProvider = DocumentationProvider.NONE;
418424
annotationLibrary = AnnotationLibrary.NONE;
419425
useJakartaEe = true;
@@ -491,7 +497,7 @@ public void processOpts() {
491497
convertPropertyToBooleanAndWriteBack(RETURN_SUCCESS_CODE, this::setReturnSuccessCode);
492498
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_UI, this::setUseSwaggerUI);
493499
convertPropertyToBooleanAndWriteBack(USE_SEALED, this::setUseSealed);
494-
if (getDocumentationProvider().equals(DocumentationProvider.NONE)) {
500+
if (DocumentationProvider.NONE.equals(getDocumentationProvider())) {
495501
this.setUseSwaggerUI(false);
496502
}
497503

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6592,7 +6592,6 @@ public void shouldImportJackson3JsonDeserializeForUniqueItemsWhenJackson3Set() t
65926592
codegen.setOpenAPI(openAPI);
65936593
codegen.setOutputDir(output.getAbsolutePath());
65946594

6595-
65966595
codegen.additionalProperties().put(SpringCodegen.USE_SPRING_BOOT4, "true");
65976596
codegen.additionalProperties().put(SpringCodegen.USE_JACKSON_3, "true");
65986597
codegen.additionalProperties().put(SpringCodegen.OPENAPI_NULLABLE, "false");
@@ -6611,4 +6610,31 @@ public void shouldImportJackson3JsonDeserializeForUniqueItemsWhenJackson3Set() t
66116610
.hasImports("tools.jackson.databind.annotation.JsonDeserialize");
66126611
}
66136612

6613+
@Test
6614+
public void shouldNotHaveDocumentationAnnotationWhenUsingLibrarySpringHttpInterface() throws IOException {
6615+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
6616+
output.deleteOnExit();
6617+
String outputPath = output.getAbsolutePath().replace('\\', '/');
6618+
6619+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore-echo.yaml");
6620+
final SpringCodegen codegen = new SpringCodegen();
6621+
codegen.setOpenAPI(openAPI);
6622+
codegen.setOutputDir(output.getAbsolutePath());
6623+
codegen.setLibrary(SPRING_HTTP_INTERFACE);
6624+
codegen.setAnnotationLibrary(AnnotationLibrary.SWAGGER2);
6625+
codegen.setDocumentationProvider(DocumentationProvider.SPRINGDOC);
6626+
6627+
ClientOptInput input = new ClientOptInput();
6628+
input.openAPI(openAPI);
6629+
input.config(codegen);
6630+
6631+
DefaultGenerator generator = new DefaultGenerator();
6632+
generator.setGenerateMetadata(false); // skip metadata generation
6633+
6634+
Map<String, File> files = generator.opts(input).generate().stream()
6635+
.collect(Collectors.toMap(File::getName, Function.identity()));
6636+
6637+
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetApi.java"))
6638+
.assertMethod("addPet").assertParameter("pet").assertParameterAnnotations().doesNotContainWithName("Parameter");
6639+
}
66146640
}

0 commit comments

Comments
 (0)