cyberrebell / api-mapping-layer-gen
The library to generate the mapping layer for your API
Installs: 120
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/cyberrebell/api-mapping-layer-gen
Requires
- php: >=7.1
- symfony/yaml: ^3.3|^4.0
- zendframework/zend-code: ^3.3
Suggests
- hanibal4nothing/simple-collection: Collection framework
README
Purpose
Library to generate an mapping interface based on an given API definition.
Useful for the initial setup of a new consumer application that needs to handle an format mapping of an already existing API / or an service that shall implement an API based on a definition.
Supported input definitions
- OpenAPI
- .yml
- .json
 
PHP
Install
$ composer require cyberrebell/api-mapping-layer-gen
Usage
Entities
<?php require 'vendor/autoload.php'; use ApiMappingLayerGen\Mapper\OpenApi\Mapper; use ApiMappingLayerGen\Generator\Php\EntityGenerator\Native; use ApiMappingLayerGen\Generator\Php\EntityBuilder; $file = '/path/to/api.yml'; $mapper = new Mapper($file); $patterns = $mapper->getPatterns(); $entityBuilder = new EntityBuilder(new Native([ 'addDocblockTypes' => true, 'addDocblockDescriptions' => false, 'useFluentSetters' => false, 'useSetterTypeHints' => true, 'useGetterTypeHints' => true, 'hideNullValues' => true ])); $entityBuilder->buildEntities($patterns, 'App', 'src/App');
schema.json
<?php require 'vendor/autoload.php'; use ApiMappingLayerGen\Mapper\OpenApi\Mapper; use ApiMappingLayerGen\Generator\JsonSchema\JsonSchemaBuilder; use ApiMappingLayerGen\Generator\JsonSchema\OpenApi\JsonSchemaGenerator; $file = '/path/to/api.yml'; $mapper = new Mapper($file); $definition = $mapper->getDefinition(); $jsonBuilder = new JsonSchemaBuilder(new JsonSchemaGenerator()); $jsonBuilder->buildSchemas($definition, __DIR__ . '/../docs/json');
Supported output formats
- PHP
- Native
- creates GeneratedEntiteswhich contain all generated functionality expected of a mapping layer
- creates Entitieswhich extend theGeneratedEntitiesand can be used to store additional functionality
- uses native PHP arrays rather than collection classes like
 
- creates 
- CollectionBased
- Same as Native but uses collection classes and also generates Collectionswhich can be extended with specific filter/search features
 
- Same as Native but uses collection classes and also generates 
 
- Native
- json-schema (http://json-schema.org/)
- Creates schema.json files which can be used for testing or validation purposes
 
License
MIT © Cyberrebell