This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Saloon SDK Generator is a Laravel Zero CLI application that generates PHP SDKs from API specifications (OpenAPI/Swagger and Postman Collections) using the Saloon HTTP client framework.
# Run the CLI in development
./codegen generate:sdk API_SPEC_FILE.{json|yaml|yml} --type={postman|openapi} [--name=SDK_NAME] [--output=OUTPUT_PATH] [--namespace=Company\\Integration] [--force] [--dry] [--zip]
# Convert Swagger v1/v2 to OpenAPI 3.0
./codegen convert old.json [output.json]# Build the Phar binary (current version: 1.3.1)
composer build
# Run tests
composer test
composer test-coverage
# Format code (Laravel Pint)
composer format
# Clean generated test output
composer clean
# Generate all sample SDKs
composer generate:allWhen preparing a new release:
-
Update version numbers:
- Update
build-versionincomposer.jsonscripts section - Build the new binary:
composer build
- Update
-
Update documentation:
- Add new version section to
CHANGELOG.mdwith:- Version number and date
- Added/Fixed/Changed sections
- Credits to contributors
- Update this file with the new version number
- Add new version section to
-
Create git tag and release:
# Commit all changes git add composer.json composer.lock CHANGELOG.md builds/sdkgenerator git commit -m "Release vX.Y.Z: Brief description" # Create tag git tag vX.Y.Z # Push changes and tag git push origin master git push origin vX.Y.Z # Create GitHub release gh release create vX.Y.Z --title "vX.Y.Z: Brief title" --notes "Release notes..."
-
Release notes format:
## What's Changed Brief description of the release. ### Added - New features ### Fixed - Bug fixes ### Changed - Breaking changes or improvements ### Credits - Thanks to @contributor for PR #XX ## Installation ```bash composer global require crescat-io/saloon-sdk-generator
Full Changelog: https://github.com/crescat-io/saloon-sdk-generator/compare/vX.Y.Y...vX.Y.Z
-
Parsers (src/Parsers/): Convert API specifications to internal format
OpenApiParser: Handles OpenAPI/Swagger specsPostmanCollectionParser: Handles Postman collections- Output:
ApiSpecificationdata object
-
Generators (src/Generators/): Create PHP SDK components
ConnectorGenerator: Main SDK connector classRequestGenerator: Individual endpoint request classesResourceGenerator: API resource grouping classesDtoGenerator: Data Transfer ObjectsBaseResourceGenerator: Base resource class
-
Data Objects (src/Data/Generator/): Internal representations
ApiSpecification: Complete API structureEndpoint: Individual API endpoint detailsParameter: Request/response parametersConfig: Generator configuration
-
CodeGenerator (src/CodeGenerator.php): Orchestrates the generation process
- Parser Interface: All parsers implement
Crescat\SaloonSdkGenerator\Contracts\Parser - Generator Interface: All generators implement
Crescat\SaloonSdkGenerator\Contracts\Generator - Factory Pattern:
Factory::parse()andFactory::registerParser()for extensibility - Laravel Zero Commands: CLI commands in src/Commands/
- Reference Resolution: Manual resolution of OpenAPI $ref references for parameters and schemas
- Header Filtering: Configurable filtering of headers managed by Saloon (Authorization, Content-Type, etc.)
- Uses Pest PHP testing framework
- Test samples in tests/Samples/
- Generated output goes to tests/Output/ (gitignored)
- Key test:
ConnectorGeneratorTestvalidates the core generation logic
- PHP 8.2+ required
- Follows PSR-4 autoloading
- Uses Laravel service container for dependency injection
- Nette PHP Generator for code generation
- Built binary distributed via Packagist as
builds/sdkgenerator
- Dependency Compatibility: Updated Laravel and termwind constraints to support newer versions
- Global Installation: Fixed conflicts when installing globally with composer
- OpenAPI $ref Resolution: Fixed issues with parameter and schema references not being resolved
- Header Filtering: Added configurable header filtering with defaults for Saloon-managed headers
- Nullable Parameters: Resource methods now have default values for nullable parameters
- Test Coverage: Added comprehensive tests for nested DTOs, header filtering, and nullable parameters
- Circular References: Parser uses RESOLVE_MODE_INLINE to avoid infinite loops
- DTO Type Prefixing: Use FQN (fully qualified namespace) to prevent backslash prefix
- Header Management: Default filtered headers: Authorization, Content-Type, Accept, Accept-Language, User-Agent