API / Minn\Rest / ClientSchema

ClientSchema final class

Minn\Rest\ClientSchema · public/minn/src/Minn/Rest/ClientSchema.php · 81 lines

A JSON schema trimmed for a client (probe json-schema): only the keywords a profile allows, in the order given, at every level a sub-schema sits.

A property's boolean required becomes its object's required list (names whose required is true), kept where the object's own required is not a list, appended last otherwise, even where the profile drops required itself; an object's own list wins. A boolean required is always dropped. Sub-schemas are trimmed where they are objects: a keyword's value, a list's members, a map's entries; anything else stays as given.

Uses 1

Constants and properties

privateDRAFT_04_FIRST = array ( 0 => '$schema', 1 => 'id', 2 => '$ref', )
privateDRAFT_04_LAST = array ( 0 => 'required', 1 => 'allOf', 2 => 'not', 3 => 'definitions', 4 => 'dependencies', 5 => 'additionalItems', )
privateMAPS = array ( 0 => 'properties', 1 => 'patternProperties', 2 => 'definitions', 3 => 'dependencies', )

Keywords whose value maps names to sub-schemas.

privateSCHEMAS = array ( 0 => 'items', 1 => 'additionalProperties', 2 => 'additionalItems', 3 => 'not', 4 => 'anyOf', 5 => 'oneOf', 6 => 'allOf', )

Keywords whose value is a sub-schema or a list of them.

Public

statickeywords(string $profile): array#

The keywords a profile keeps: draft-04's whole set, the REST API's for any other profile.

@return list<string>
statictrim(array $schema, array $allowed): array#

A schema with only the allowed keywords, keyed by keyword (the values do not matter), trimmed all the way down.

$schemaarray<array-key, mixed>
$allowedarray<array-key, mixed>
@return array<array-key, mixed>

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateposition(mixed $value, array $allowed): mixed#

A sub-schema's place: an object trimmed, a list's object members trimmed, anything else as given.

privatemember(mixed $value, array $allowed): mixed#

A list member or map entry: trimmed when it is an object schema.

privaterequiredNames(array $schema): array#
@return list<string> the properties whose required is true