Besides simply parsing your OpenAPI into Validated objects,
the reader is designed to simplify the developer experience of other OpenAPI tools.
Properties should be safe to access:
All properties have a value.
null represents an omitted field if no other value can be safely assumed.
Data structures should be easily discoverable. All properties should have strong typehints.
The false boolean schema explicitly states any input will fail.
The Reader will narrow schemas to false if it is proven impossible to pass.
This optimizes code that may otherwise validate input that will always fail.
Any schema specifying an empty enum, is narrowed to the false boolean schema.
If enum is specified, it contains the exhaustive list of valid values.
If enum is specified as an empty array, there are no valid values.
If a schema specifies enum without a value that passes the rest of the schema;
it is impossible to pass, it will be narrowed to the false boolean schema.
Typehints are narrowed if it has no impact on expressiveness.
allOf, anyOf and oneOf can express two things:
- There are subschemas
- There are not
To express there are no subschemas, the value is omitted.
As such, the Reader structures allOf, anyOf and oneOf in two ways:
- A non-empty array
- An empty array
Though these keywords are not allowed to be empty, The Reader allows it for the sake of simplicity.
This simplifies code that loops through subschemas.
Optional metadata is expressed in two ways:
- There is data
- There is not
As such, the Reader structures metadata in two ways:
- A string containing non-whitespace characters
- An empty string
''
When accessing string metadata only one check is necessary:
if ($metadata !== '') {
// do something...
}Data is combined, if and only if, it has no impact on expressiveness.
A numerical limit can only be expressed in three ways:
- There is no limit
- There is an inclusive limit
- There is an exclusive limit
As such the Reader combines the relevant keywords into:
Limit|null $maximum.Limit|null $minimum.
Where Limit has two properties:
float|int $limitbool $exclusive
The more restrictive keyword takes precedence.