api-clients / resource-generator
Resource from YAML generation tool
Installs: 32 315
Dependents: 17
Suggesters: 1
Security: 0
Stars: 2
Watchers: 5
Forks: 1
Open Issues: 6
Requires
- php: ^7.0
- api-clients/foundation: ^1.0
- api-clients/hydrator: ^1.0
- api-clients/resource: ^3.0
- api-clients/resource-test-utilities: ^1.0
- doctrine/inflector: ^1.1
- friendsofphp/php-cs-fixer: ^2.3
- nikic/php-parser: ^3.0 || ^2.1
- symfony/yaml: ^2.8||^3.0
Requires (Dev)
- dev-master
- 1.0.2
- 1.0.1
- 1.0.0
- 0.9.0
- dev-renovate/configure
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/friendsofphp/php-cs-fixer-2.17.1
- dev-improvement-chop-down-code-x-mass-three
- dev-var.ci
- dev-feature-wrap-data-into-classes
- dev-feature-handle-renames
- dev-ci-appveyor-lesstrict-filecomparison
- dev-feature-collection-annotation
- dev-feature-tested-objects-annotations
- dev-php-strict-type-fix
This package is auto-updated.
Last update: 2024-12-15 08:17:47 UTC
README
Goals
- Tool for easy wireframing of resources for
wyrihaximus/api-client
based API clients
Installation
To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^
.
composer require api-clients/resource-generator
Usage
Pas a definition
YAML
file.
./vendor/bin/api-client-resource-generator [definition]
For example:
./vendor/bin/api-client-resource-generator ./yaml/project.yml
YAML
The YAML
format allows for quick and easy generation of resources, empty resources, and resource tests. The spec consists out of two or more files.
resource.yaml
First there is the resource.yml
file with the meta data regarding all resources:
yaml_location: yaml # The location where the YAML files for the Resources are api_settings: Example\Client\ApiSettings # API Settings file location src: # SRC path: src/Resources # Path where the resources should be placed namespace: Example\Client\Resource # The namespace for the resources tests: # TESTS path: tests/Resources # Path where the resources tests should be placed namespace: Example\Tests\Client\Resource # The namespace for the tests
yaml/project.yaml
The following YAML
is an example resource file:
class: Project # Resource classname properties: # The resource's properties id: int # Simple id field with type int name: string # Any scalar types or classes work plugins: SplObjectStorage # builds: # But differet types `special` properties are supported. type: array # For example the collection expects the type to be an array annotations: # and it uses an annotation name `collection` to collection: Project\Build # transform all items in the array to the specified resource. latestBuild: # Another supported annotation is `nested`, `nested` allows you to type: Project\Build # turn a properties that would otherwise be an array into a annotations: # resource. With it's own properties and methods nested: Project\Build # updated: # Normally all methods are generated to their camelCase property name method: updatedAt # but with `method` you can specify a custom method type: DateTimeInterface # When for example dealing with time, you can specify to return an interface wrap: DateTimeImmutable # while wrapping the value in a concrete class
License
The MIT License (MIT)
Copyright (c) 2016 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.