Do not ignore multiple types when serializing to 3.0#2960
Conversation
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer, | ||
| }; |
There was a problem hiding this comment.
Before my change, this was resulting in an empty schema, which will match anything.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer | JsonSchemaType.Null, |
There was a problem hiding this comment.
Before my change, the type was ignored, and only anyOf was emitted.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer, |
There was a problem hiding this comment.
Before my change, the type was ignored and only anyOf was emitted.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer | JsonSchemaType.Null, |
There was a problem hiding this comment.
Before my change, the type was ignored and only oneOf was emitted.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer, |
There was a problem hiding this comment.
Before my change, only oneOf was emitted.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer | JsonSchemaType.Null, |
There was a problem hiding this comment.
Before my change, an empty schema was generated, allowing anything to match.
165e0eb to
a663f6f
Compare
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer, |
There was a problem hiding this comment.
In this test, the behavior is the same as in the past. We are not respecting Type, and I can't see an easy way to respect it.
It's technically possible to emit "allOf" that contains a schema representing the types as "oneOf" or "anyOf" schema, and then another schema that wraps the existing anyOf/oneOf. But that's a major re-write I didn't want to introduce.
| { | ||
| var schema = new OpenApiSchema() | ||
| { | ||
| Type = JsonSchemaType.String | JsonSchemaType.Integer | JsonSchemaType.Null, |
There was a problem hiding this comment.
Same here. This wasn't (and is still not) respected. We could respect it but it will be a more bigger re-write.
Fixes #2939
ToSingleIdentifieris only a simplification to make it easier to read.Typehad multiple values (e.g, String and Integer). This is now handled usingoneOforanyOf(whichever isn't used by the current schema already). If both are used, we ignore as it we used to in the past.Type.Nullfrom it (if it exists).For context: https://spec.openapis.org/oas/v3.0.4.html#json-schema-keywords