-
Notifications
You must be signed in to change notification settings - Fork 64
Description
According to the JSON schema spec
AnyOf
An instance validates successfully against this keyword if it
validates successfully against at least one schema defined by this
keyword's value.
OneOf
An instance validates successfully against this keyword if it
validates successfully against exactly one schema defined by this
keyword's value.
There are a number of places where the conversion library is using anyOf when it should be using instead oneOf, and it seems the confusion originates from the early days of the library, as this comment would indicate.
If we take the example of OData double to illustrate this issue, the library currently produces this.
zoom:
anyOf:
- type: number
- type: string
- enum:
- '-INF'
- INF
- NaN
format: double
nullable: trueWhich could be translated to a human sentence to "any instance that is a number (rational) or a string or -INF or INF or NaN is a double".
But the missing details here is that we're using "or" and not "xor" (exclusive or).
Semantically speaking, the value will (and should) never be a number AND -INF for example.
I believe the right human sentence should be "any instance that is a number (rational) or a string or -INF or INF or NaN to exactly one of these options is a double". Which would result in the following.
zoom:
oneOf:
- type: number
- type: string
- enum:
- '-INF'
- INF
- NaN
format: double
nullable: trueThis is even more evident with the geometric data structures where a geometric information can be a point or a line but not both (mathematically speaking, a line is defined a continuous set of points).
OpenAPI.NET.OData/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSpatialTypeSchemaGenerator.cs
Lines 217 to 225 in bdf4241
| AnyOf = new List<OpenApiSchema> | |
| { | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryPoint" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryLineString" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryPolygon" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryMultiPoint" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryMultiLineString" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryMultiPolygon" } }, | |
| new OpenApiSchema { UnresolvedReference = true, Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Edm.GeometryCollection" } } |
TODO
- update geometric points (link above) to oneOf
- update decimal and down to oneOf
- update unit and integration tests
- (optional) make components for Edm double, decimal and single