dealroadshow / kodegen
Generates PHP classes from json schema, including Kubernetes json schema
Requires
- php: >=8.0
- ext-ctype: *
- ext-iconv: *
- ext-json: *
- guzzlehttp/psr7: ^2.0
- knplabs/github-api: ^3.0@dev
- nette/php-generator: ^3.5
- symfony/console: >=5.2
- symfony/dotenv: >=5.2
- symfony/flex: ^1.11
- symfony/framework-bundle: >=5.2
- symfony/http-client: >=5.2
- symfony/maker-bundle: ^1.20
- symfony/yaml: >=5.2
Conflicts
README
This project provides cli to generate PHP classes for Kubernetes API objects. It uses official Kubernetes API json schema in order to generate classes for all API objects that corresponding Kubernetes version provides.
Installation
The recommended way to install Kodegen is Composer.
Install kodegen
cli globally and use it anywhere, as long as Composer
vendor/bin
directory is in your PATH
.
Usually this dir is $HOME/.composer/vendor/bin
.
composer global require dealroadshow/kodegen
Usage
For generic json schemas
In order to generate PHP code from generic json schema, just run the following command:
kodegen json-schema:generate:php path/to/json-schema-file.json
It will guide you through the generation process interactively.
For Kubernetes json schema
At first you want to determine the latest API versions for chosen Kubernetes version. For example, the latest json schema version for Kubernetes v1.20 is v1.20.10. In order to get this versions, run command:
k8s:schema:versions [number of latest Kubernetes versions].
The output of this command may look like follows:
kodegen k8s:schema:versions 4
{"v1.19":"v1.19.14","v1.20":"v1.20.10","v1.21":"v1.21.4","v1.22":"v1.22.0"}
After that you may use this json to retrieve Kubernetes json schema:
export DEALROADSHOW_KODEGEN_JSON_SCHEMA_VERSIONS='{"v1.19":"v1.19.14","v1.20":"v1.20.10","v1.21":"v1.21.4","v1.22":"v1.22.0"}'
kodegen k8s:schema:fetch /tmp/kubernetes-schema.json
The command above will let you chose one on Kubernetes versions, defined in DEALROADSHOW_KODEGEN_JSON_SCHEMA_VERSIONS
env variable.
When you have your Kubernetes json schema, you can generate PHP classes from it:
kodegen k8s:generate:php /tmp/kubernetes-schema.json
This command will guide you through the generation process interactively.