Skip to content

Schema building ​

Schema building turns validation rules into a JSON schema that the UI uses for the body editor, live validation and auto fill. The same value objects describe response shapes.

Rules to schema ​

Laravel rulesRulesetProduced by an extraction strategy.
Build the treeSchemaBuilderTurns paths such as user.name or tags.* into objects and arrays.
Map each fieldRuleToSchemaMapperSmall processors handle enums, formats, lookups, conditions and rule objects.
Create the propertyPropertyBuilderOne value object for each type.
Mark file fieldsBinaryContentInferrer
SchemaSchemaCarries hints and an optional extraction error.

The processors live in Services/RulesMapper/Processors.

Labels from the attributes() method of a Form Request and keys added in prepareForValidation() are read by ReadFormRequestHooksAction. A merged key becomes optional.

Response shapes ​

The UI asks for the shape of a response through the response shape endpoint.

Response shape endpointResponseSchemaExtractor
Tried in this order until one applies
Paginated collectionPaginatedResourceCollectionStrategy
JSON resourceJsonResourceStrategy
Data objectSpatieDataObjectResponseStrategy
Raw JSONRawJsonResponseStrategy
Response schema

The resource strategies read the toArray() body through the AST. Where possible they guess the Eloquent model, from the docblock or the resource name, to take column types from the database.

When no strategy applies, InferSchemaFromArrayAction builds the schema from the real response body that the UI sends.

Adding a rule processor ​

  1. Add a class in Services/RulesMapper/Processors.
  2. Call it from RuleToSchemaMapper.
  3. Cover it with a functional test that feeds rules and asserts the mapped property.

Previous step is route extraction.