{"id":32304704,"url":"https://github.com/valgene/valgene-cli","last_synced_at":"2025-10-23T06:36:57.631Z","repository":{"id":62458525,"uuid":"156379813","full_name":"valgene/valgene-cli","owner":"valgene","description":"Multi language validation code and DTO generator from OpenAPI specification.","archived":false,"fork":false,"pushed_at":"2019-05-22T11:18:43.000Z","size":87,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-23T06:36:47.809Z","etag":null,"topics":["cli","developer-tools","dto","generator","openapi","php","swagger","swagger-codegen","tool"],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/valgene_cli","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/valgene.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-06T12:24:11.000Z","updated_at":"2023-02-09T14:31:42.000Z","dependencies_parsed_at":"2022-11-02T00:32:08.618Z","dependency_job_id":null,"html_url":"https://github.com/valgene/valgene-cli","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/valgene/valgene-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valgene%2Fvalgene-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valgene%2Fvalgene-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valgene%2Fvalgene-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valgene%2Fvalgene-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valgene","download_url":"https://codeload.github.com/valgene/valgene-cli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valgene%2Fvalgene-cli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280577141,"owners_count":26354072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","developer-tools","dto","generator","openapi","php","swagger","swagger-codegen","tool"],"created_at":"2025-10-23T06:36:54.898Z","updated_at":"2025-10-23T06:36:57.626Z","avatar_url":"https://github.com/valgene.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Valgene CLI\n\n[![Build Status](https://travis-ci.org/valgene/valgene-cli.svg?branch=master)](https://travis-ci.org/valgene/valgene-cli#)\n[![Coverage Status](https://coveralls.io/repos/github/valgene/valgene-cli/badge.svg?branch=master)](https://coveralls.io/github/valgene/valgene-cli?branch=master)\n[![Pub](https://img.shields.io/pub/v/valgene_cli.svg)](https://pub.dartlang.org/packages/valgene_cli)\n\n## Introduction\n\nassuming you are providing some RESTful/Web APIs, then you are familiar with the tasks of\n\n- documenting the API\n- validating incoming data against the API specification\n- creating [DTOs](https://martinfowler.com/eaaCatalog/dataTransferObject.html) for dedicated API endpoints\n\nSomehow these things are disconnected to each other, that means the documentation of the API is normally not used for validating incoming data. Neither it is used for writing a DTO class. As well all the tasks are repetitive, manual and error prone.\n\nThis is where Valgene kicks in and reduces a lot of pain.\n\n## Usage\n\nValgene (Validation Generator) generates validator and DTO boiler plate code from \n your [OpenAPI](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md) specs.\n\n### Given\n\nso lets assume you have an API spec [like the following](https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml) that defines 1 endpoint that accepts incoming data, that is `[POST] /pets`.\n```yaml\npaths:\n  /pets:\n    post:\n      description: Creates a new pet in the store.  Duplicates are allowed\n      operationId: addPet\n      requestBody:\n        description: Pet to add to the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/NewPet'\n```\n\nThe payload of the endpoint is expected to be like:\n```yaml\nNewPet:\n  required:\n    - name  \n  properties:\n    name:\n      type: string\n    tag:\n      type: string    \n```\n\n### When\n\nwhen invoking valgene  \n```bash\nvalgene --template php5.5 --spec petstore-expanded.yaml --option 'php.namespace:\\My\\PetStore\\Api'\n```\n\n### Then\n\nit will generate a Validator, DTO and some Exception classes:\n\n```bash\nvalgene --template php5.5 --spec petstore-expanded.yaml --option 'php.namespace:\\My\\PetStore\\Api'\n\u003e processing petstore-expanded.yaml:\n  - route [POST]    /pets\n\u003e generating:\n  - PostAddPet/NewPetDto.php\n  - PostAddPet/NewPetDtoValidator.php\n  - Exception/MissingFieldException.php\n  - Exception/FieldException.php\n  - Exception/InvalidFieldException.php\n```\n\nGenerated Validator looks like this:\n```php\n\u003c?php\n\nnamespace \\My\\PetStore\\Api\\PostAddPet;\n\nuse \\My\\PetStore\\Api\\Exception\\InvalidFieldException;\nuse \\My\\PetStore\\Api\\Exception\\MissingFieldException;\n\n/**\n * GENERATED CODE - DO NOT MODIFY BY HAND\n */\nclass NewPetDtoValidator\n{\n    /**\n     * @param array $json\n     * @throws MissingFieldException\n     * @throws InvalidFieldException\n     */\n    public function validate($json)\n    {\n        $this-\u003eisNameValid($json, true);\n        $this-\u003eisTagValid($json, false);\n    }\n\n    /**\n     * @param array $json\n     * @param bool $isRequired\n     */\n    protected function isNameValid($json, $isRequired)\n    {\n        $field = NewPetDto::PROPERTY_NAME;\n        if (!array_key_exists($field, $json)) {\n            if ($isRequired) {\n                throw new MissingFieldException($field, $json);\n            }\n        }\n        $value = $json[$field];\n\n        if (!is_string($value)) {\n            throw new InvalidFieldException($field, $json, 'datatype is not string');\n        }\n    }\n\n    /**\n     * @param array $json\n     * @param bool $isRequired\n     */\n    protected function isTagValid($json, $isRequired)\n    {\n        $field = NewPetDto::PROPERTY_TAG;\n        if (!array_key_exists($field, $json)) {\n            if ($isRequired) {\n                throw new MissingFieldException($field, $json);\n            }\n        }\n        $value = $json[$field];\n\n        if (!is_string($value)) {\n            throw new InvalidFieldException($field, $json, 'datatype is not string');\n        }\n    }\n}\n```\n\nGenerated DTO looks like this:\n\n```php\n\u003c?php\n\nnamespace \\My\\Sample\\Api\\PostPets;\n\n/**\n * GENERATED CODE - DO NOT MODIFY BY HAND\n */\nclass NewPetDto\n{\n    const PROPERTY_NAME = 'name';\n    const PROPERTY_TAG = 'tag';\n\n    /** @var string $name */\n    public $name;\n\n    /** @var string $tag */\n    public $tag;\n\n    /**\n     * @param array $payload\n     * @return NewPetDto\n     */\n    public static function fromArray(array $payload)\n    {\n        $self = new static();\n        $self-\u003ename = $payload[static::PROPERTY_NAME];\n        $self-\u003etag = $payload[static::PROPERTY_TAG];\n\n        return $self;\n    }\n}\n```\n\n## Customization of Templates\n\nBe aware that the finally generated code is totally customizable and the shown example is very opinionated.\nTo enable your custom Templates you copy the files from the [template folder](https://github.com/valgene/valgene-cli/tree/master/templates/php5.5) to a folder on you local disk. Then you can customize them and pass the path of the folder as an argument like:\n\n```bash\nvalgene --template-folder $PWD/my-custom-php-templates --spec petstore-expanded.yaml --option 'php.namespace:\\My\\PetStore\\Api'\n```\n\nFurther reading of variables available in templates you can find [here](doc/templates.md)\n\n## Installation\n\n[the dart way](https://www.dartlang.org/tools/pub/cmd/pub-global#activating-a-package-on-your-local-machine):\n```bash\npub global activate valgene_cli\n```\n\n## Generating code for other languages\n\nas seen above there is a `--template` parameter that allows to switch the generated language/template.\n```bash\nvalgene --template php5.5 --spec petstore-expanded.yaml --option 'php.namespace:\\My\\PetStore\\Api'\n```\n\nIn fact the code generators itself are just a couple of templates that getting rendered by the valgene engine.\nThe template language itself is [Mustache](https://mustache.github.io/) and therefore you can customize the code that is generated pretty easy.\n\n## Things to be done\n\n- add support for API specs in other formats such as JSON\n- add support for a config file that lives in a own project to save the command line args\n- providing templates for other languages like Java\n- working on a IDE integration for VS Code and IntelliJ to automate things even further\n- full fledged package that can be run standalone (especially in the IDE for integration)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalgene%2Fvalgene-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalgene%2Fvalgene-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalgene%2Fvalgene-cli/lists"}