Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blueprints parser, mapper, and validator autogenerated from JSON Sche…
…ma (#23) Solves the Blueprint parsing problem as follows: * JSON Schema is the source of truth for the Blueprint data structure * Model classes are generated from JSON Schema * Input Validation is done against the JSON Schema * Mapping validated input into model instances is indirectly done based on the JSON Schema ## Summary of the approach We use [Janephp](https://github.com/janephp/janephp/) to infer the PHP model class structure from the JSON schema We then use Jane's output to generate PHP code using [Nette PHP generator](https://github.com/nette/php-generator): * Model classes * Interfaces for groups of related classes: `StepDefinitionInterface`, `ResourceDefinitionInterface`. * Interface resolution map for the [JsonMapper library](https://jsonmapper.net/). * PHP docstrings with more accurate types than Jane to guide the mapping process From there, the data pipeline looks as follows: 1. Parse raw JSON 2. Validate it with Opis 3. Map it into PHP models using JsonMapper Or, if you're consuming the PHP API directly: 1. Create Model instances 2. Validate them with Opis ## Remaining work - [ ] Solve merge conflicts ## Rationale Parsing and mapping JSON [in TypeScript is a simple problem, but in PHP it's surprisingly involved](WordPress/blueprints#13 (comment)). This PR combines three previously explored approaches into a single pipeline: * WordPress/blueprints#17 * WordPress/blueprints#19 * WordPress/blueprints#21
- Loading branch information