Skip to content

Commit d68a186

Browse files
authored
test(OpenAPINormalizer): nullability normalization for 3.1 specs (#19714)
* test(OpenAPINormalizer): nullability normalization for 3.1 specs * chore: samples
1 parent 2d57255 commit d68a186

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,24 @@ public void testOpenAPINormalizerProcessingArraySchema31Spec() {
624624
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
625625
}
626626

627+
@Test
628+
public void testOpenAPINormalizerProcessingArraySchema31NullabilitySpec() {
629+
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/null-types-simple.yaml");
630+
Schema schema = openAPI.getComponents().getSchemas().get("WithNullableType");
631+
632+
assertNull(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
633+
assertNull(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
634+
assertNull(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());
635+
636+
Map<String, String> inputRules = Map.of("NORMALIZE_31SPEC", "true");
637+
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules);
638+
openAPINormalizer.normalize();
639+
640+
assertTrue(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
641+
assertTrue(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
642+
assertTrue(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());
643+
}
644+
627645
@Test
628646
public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
629647
// to test the rule SIMPLIFY_ONEOF_ANYOF with 3.1 spec

samples/client/others/typescript/builds/null-types-simple/.gitattributes

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/http/http.ts

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)