[openapi-normalizer] Fix nullable boolean check in oneOf schema (#15276)

* fix nullable boolean check in oneof

* minor fix

* fix spec
This commit is contained in:
William Cheng 2023-04-22 16:39:12 +08:00 committed by GitHub
parent b5745e6f26
commit e51908f176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -691,7 +691,7 @@ public class OpenAPINormalizer {
// if only one element left, simplify to just the element (schema) // if only one element left, simplify to just the element (schema)
if (schema.getOneOf().size() == 1) { if (schema.getOneOf().size() == 1) {
if (schema.getNullable()) { // retain nullable setting if (Boolean.TRUE.equals(schema.getNullable())) { // retain nullable setting
((Schema) schema.getOneOf().get(0)).setNullable(true); ((Schema) schema.getOneOf().get(0)).setNullable(true);
} }
return (Schema) schema.getOneOf().get(0); return (Schema) schema.getOneOf().get(0);

View File

@ -55,9 +55,27 @@ components:
number: number:
anyOf: anyOf:
- $ref: '#/components/schemas/Number' - $ref: '#/components/schemas/Number'
ParentWithOneOfProperty:
type: object
properties:
number:
oneOf:
- $ref: '#/components/schemas/Number'
ParentWithPluralOneOfProperty:
type: object
properties:
number:
oneOf:
- $ref: '#/components/schemas/Number'
- $ref: '#/components/schemas/Number2'
Number: Number:
enum: enum:
- one - one
- two - two
- three - three
type: string type: string
Number2:
enum:
- one
- two
type: string