elsevier-io / json-schema-php-generator
Lib to generate a PHP representation of the data structures in a JSON Schema
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 3 154
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 28
Forks: 1
Open Issues: 1
Requires
- php: ~7.0 || ~8.1
- ext-json: *
- ext-mbstring: *
- justinrainbow/json-schema: ^5.2
- league/flysystem: ^2.0
- monolog/monolog: ^2.7
- nette/php-generator: ^3.5
- nette/utils: ^3.2
- psr/log: ^1.0
- symfony/console: ^4.4||^5.4
Requires (Dev)
- hamcrest/hamcrest-php: ^2.0
- json-schema/json-schema-test-suite: 1.3.0
- phpunit/phpunit: ^4.8.36
- squizlabs/php_codesniffer: ^3.1
README
Tool to generate PHP representations of the data structures in a JSON Schema. Entities in the JSON schema are represented
by PHP DTOs. Required properties are added via the constructor (respecting the order if it is defined in the JSON) and optional
properties are added via setters. See the tests/examples
folder for examples of the PHP created (these examples are used
by the tests).
There is a command-line script to run the tool:
./bin/php-json-schema-generate
Running it without any args or options will give you usage docs.
So far this is only a partial implementation of the JSON Schema. See tests for which aspects have been implemented.
TODOs
- Add more console logging to command
- Add warning/confirm step to console command about file delete
- Add option to read configs from file rather than pass in as args
- Make namespace argument optional (and hence create output without any namespaces)
- Add support for nulls
- Ensure generator can handle all valid JSON Schemas (Schemata?)
- Parse schema to AST before generating code (so we can create different code generators)
- Add option to toggle between swallowing invalid values and throwing in generated code