|
28 | 28 | import org.apache.commons.lang3.StringUtils; |
29 | 29 | import org.assertj.core.api.Assertions; |
30 | 30 | import org.assertj.core.api.MapAssert; |
| 31 | +import org.junit.jupiter.api.DisplayName; |
31 | 32 | import org.openapitools.codegen.*; |
32 | 33 | import org.openapitools.codegen.config.CodegenConfigurator; |
33 | 34 | import org.openapitools.codegen.config.GlobalSettings; |
@@ -6637,4 +6638,33 @@ public void shouldNotHaveDocumentationAnnotationWhenUsingLibrarySpringHttpInterf |
6637 | 6638 | JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetApi.java")) |
6638 | 6639 | .assertMethod("addPet").assertParameter("pet").assertParameterAnnotations().doesNotContainWithName("Parameter"); |
6639 | 6640 | } |
| 6641 | + |
| 6642 | + @Test |
| 6643 | + @DisplayName("Testing Issue #23206: Support JSpecify with SchemaMappings") |
| 6644 | + public void testIssue23206() throws IOException { |
| 6645 | + final SpringCodegen codegen = new SpringCodegen(); |
| 6646 | + |
| 6647 | + codegen.setLibrary("spring-boot"); |
| 6648 | + |
| 6649 | + codegen.importMapping().put("org.springframework.lang.Nullable", "org.jspecify.annotations.Nullable"); |
| 6650 | + codegen.schemaMapping().put("PersonCountValue", "a.b.c.PersonCountValue"); |
| 6651 | + |
| 6652 | + codegen.additionalProperties().put(OPENAPI_NULLABLE, "false"); |
| 6653 | + codegen.additionalProperties().put(SKIP_DEFAULT_INTERFACE, "true"); |
| 6654 | + codegen.additionalProperties().put(USE_SPRING_BOOT4, "true"); |
| 6655 | + codegen.additionalProperties().put(USE_JACKSON_3, "true"); |
| 6656 | + codegen.additionalProperties().put(USE_TAGS, "true"); |
| 6657 | + codegen.additionalProperties().put(USE_BEANVALIDATION, "false"); |
| 6658 | + |
| 6659 | + final Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/spring/issue_23206.yaml"); |
| 6660 | + final var javaFileAssert = JavaFileAssert.assertThat(files.get("MyDto.java")); |
| 6661 | + |
| 6662 | + javaFileAssert |
| 6663 | + .hasImports("org.jspecify.annotations.Nullable") |
| 6664 | + .assertProperty("men"); |
| 6665 | + |
| 6666 | + // Should Fail without any changes to the mustache templates! |
| 6667 | + javaFileAssert.fileContains("private a.b.c.@Nullable PersonCountValue men;"); // Actual: private @Nullable a.b.c.PersonCountValue men; |
| 6668 | + javaFileAssert.fileContains("private a.b.c.@Nullable PersonCountValue women;"); // Actual: private @Nullable a.b.c.PersonCountValue women; |
| 6669 | + } |
6640 | 6670 | } |
0 commit comments