Skip to content

Commit 5379370

Browse files
committed
fix spring-http-interface created swagger annotations
1 parent 0869cad commit 5379370

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,23 @@ public void processOpts() {
410410

411411
convertPropertyToTypeAndWriteBack(REQUEST_MAPPING_OPTION, RequestMappingMode::valueOf, this::setRequestMappingMode);
412412

413-
// Please refrain from updating values of Config Options after super.ProcessOpts() is called
414-
super.processOpts();
415-
416413
if (SPRING_HTTP_INTERFACE.equals(library)) {
417414
documentationProvider = DocumentationProvider.NONE;
418415
annotationLibrary = AnnotationLibrary.NONE;
419416
useJakartaEe = true;
420417
useBeanValidation = false;
421418
performBeanValidation = false;
422419

423-
additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);
424420
additionalProperties.put(USE_BEANVALIDATION, useBeanValidation);
425421
additionalProperties.put(PERFORM_BEANVALIDATION, performBeanValidation);
426-
additionalProperties.put(DOCUMENTATION_PROVIDER, documentationProvider.toCliOptValue());
427-
additionalProperties.put(documentationProvider.getPropertyName(), true);
428-
additionalProperties.put(ANNOTATION_LIBRARY, annotationLibrary.toCliOptValue());
429-
additionalProperties.put(annotationLibrary.getPropertyName(), true);
430-
431-
applyJakartaPackage();
432422

433423
LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary, useBeanValidation, performBeanValidation. "
434424
+ "useJakartaEe defaulted to 'true'");
435425
}
436426

427+
// Please refrain from updating values of Config Options after super.ProcessOpts() is called
428+
super.processOpts();
429+
437430
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
438431
LOGGER.warn("The springfox documentation provider is deprecated for removal. Use the springdoc provider instead.");
439432
}

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)