Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,24 @@ public void testOpenAPINormalizerProcessingArraySchema31Spec() {
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
}

@Test
public void testOpenAPINormalizerProcessingArraySchema31NullabilitySpec() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/null-types-simple.yaml");
Schema schema = openAPI.getComponents().getSchemas().get("WithNullableType");

assertNull(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
assertNull(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
assertNull(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());

Map<String, String> inputRules = Map.of("NORMALIZE_31SPEC", "true");
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules);
openAPINormalizer.normalize();

assertTrue(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
assertTrue(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
assertTrue(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding the unit test

do we still need the samples generated by bin/configs/typescript-consolidated-nullable.yaml ?

(we want to avoid too many samples as the project now contains many files that it will take quite a while to clone)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given there is not a single example with an optional array that started showing this issue in any way I'd suggest to keep the sample, however, we could combine a few samples together to reduce the footprint, as a lot of samples only show a specific issue in a property. It does make it slightly harder to work with and debug though, when trying to find an issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could combine a few samples together to reduce the footprint, as a lot of samples only show a specific issue in a property.

good idea

you may consider adding the Echo API client tests for typescript client generator and starting add these test cases to a customized version of echo api spec. used by typescript generator only.

https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#echo-server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I am trying to understand how these would help the issue - looking at the sample from #14442 we'd still check in the generated code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of creating a separate spec to test nullable array, one can copy the echo api client spec and add the test case for nullable array instead for typescript echo api client.

in other words, you can consolidate all these different test cases into echo api spec instead.

@Test
public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
// to test the rule SIMPLIFY_ONEOF_ANYOF with 3.1 spec
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.