Skip to content

Commit

Permalink
fix: error during allOf clean-up for invalid schema (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner authored Apr 28, 2023
1 parent 24e7eec commit 6512f11
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### `jsonschema-generator`
#### Fixed
- avoid error being thrown in `allOf` clean-up for invalid payload

## [4.31.0] - 2023-04-22
### `jsonschema-generator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,13 @@ private Supplier<JsonNode> returnOverlapOfStringsOrStringArrays(List<JsonNode> n
// invalid node; abort merge
return null;
}
encounteredValues.retainAll(nextValues);
if (encounteredValues.isEmpty()) {
if (encounteredValues.size() > 1) {
encounteredValues.retainAll(nextValues);
if (encounteredValues.isEmpty()) {
// invalid merge result: no valid value remained; abort merge
return null;
}
} else if (!nextValues.contains(encounteredValues.get(0))) {
// invalid merge result: no valid value remained; abort merge
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,23 @@ static Stream<Arguments> parametersForTestAllOfCleanUp() {
+ "\"allOf\": [{ \"title\":\"same in all three\" }, { \"title\":\"same in all three\" }] }",
"{ \"type\": \"object\", \"title\":\"same in all three\" }"),
Arguments.of(schemaVersion,
"{ \"type\": \"object\",\"allOf\": [{ \"title\":\"from allOf[0]\" }, { \"description\":\"from allOf[1]\" }] }",
"{ \"type\": \"object\", \"title\":\"from allOf[0]\", \"description\":\"from allOf[1]\" }")
"{ \"type\": \"object\", \"allOf\": [{ \"title\":\"from allOf[0]\" }, { \"description\":\"from allOf[1]\" }] }",
"{ \"type\": \"object\", \"title\":\"from allOf[0]\", \"description\":\"from allOf[1]\" }"),
Arguments.of(schemaVersion,
"{ \"type\": \"object\", \"allOf\": [{ \"type\": [\"object\",\"null\"] }] }",
"{ \"type\": \"object\" }"),
Arguments.of(schemaVersion,
"{ \"type\": [\"object\",\"null\"], \"allOf\": [{ \"type\": \"object\" }] }",
"{ \"type\": \"object\" }"),
Arguments.of(schemaVersion,
"{ \"type\": \"object\", \"allOf\": [{ \"type\": \"null\" }] }",
"{ \"type\": \"object\", \"allOf\": [{ \"type\": \"null\" }] }"),
Arguments.of(schemaVersion,
"{ \"type\": \"object\", \"allOf\": [{ \"type\": [\"string\",\"null\"] }] }",
"{ \"type\": \"object\", \"allOf\": [{ \"type\": [\"string\",\"null\"] }] }"),
Arguments.of(schemaVersion,
"{ \"type\": [\"object\",\"null\"], \"allOf\": [{ \"type\": \"string\" }] }",
"{ \"type\": [\"object\",\"null\"], \"allOf\": [{ \"type\": \"string\" }] }")
))
.collect(Collectors.toList());

Expand Down

0 comments on commit 6512f11

Please sign in to comment.