Generate a PHP SDK for API's using JSON:API
./bin/jsonapi-sdk generate ./openapi.json --output=../my-sdk/ --force For more information on the command options run jsonapi-sdk generate --help.
It will list all these command options:
Options:
-o, --output=OUTPUT Output directory for generated SDK [default: "./output"]
--foundation Generate Foundation support files
--connector-name=CONNECTOR-NAME Name of the Connector class (e.g., "TimaticConnector").
Config key is derived from this (e.g., "timatic").
Required when using --foundation
--base-url=BASE-URL Default base URL for the API.
--skip-tests Skip generating Pest tests
--skip-factories Skip generating Faker factories
--dry-run Show what would be generated without writing files
--force Overwrite existing files
When you run the command for the first time, you should add the --foundation flag.
This will add all the necessary files that are 'static' and these can be changed manually afterward.
Recommended first-time setup
- Create your project, e.g.
git init - Initialize Composer
composer init, this generator depends on the psr-4 autoload namespace and the package name. - Then run the generator with
--foundation.
./bin/jsonapi-sdk generate ./openapi.json \
--output=../my-sdk/ \
--foundation \
--connector-name "MyConnector" \
--base-url="https://api.myapp.com" \What --foundation does comes down to:
- Verifies a
composer.jsonexists and checks if it contains a PSR-4autoloadsection. - Runs
composer requireto add runtime dependencies likesaloonphp/saloon,nesbot/carbon,saloonphp/pagination-plugin - Runs
composer require --devto add development dependencies like:faker,pest,pintandlarastan - Updates your
composer.jsonwith PSR-4 autoload mappings - Adds composer scripts
test,coverage,formatandanalyse - Enables the Pest plugin in
config.allow-plugins.