Download the PHP package yeab/laravel-api-contract without Composer
On this page you can find all versions of the php package yeab/laravel-api-contract. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yeab/laravel-api-contract
More information about yeab/laravel-api-contract
Files in yeab/laravel-api-contract
Package laravel-api-contract
Short Description Define API contracts in your Laravel application and generate TypeScript types, API clients, SDKs, OpenAPI specs, Postman collections, and more.
License MIT
Informations about the package laravel-api-contract
Laravel API Contract
The ultimate "Write once. Generate everything." toolkit for Laravel APIs.
π Introduction
Laravel API Contract is an advanced, fully automated architecture utility for Laravel applications. It statically analyzes your existing Laravel routes, controllers, Form Requests, and API Resources to automatically generate a comprehensive API Contract.
From this single source of truth, it instantly generates Swagger documentation, TypeScript interfaces, typed API clients, Postman collections, Markdown docs, PHPUnit feature tests, and backwards-compatibility reports.
π― Core Philosophy
"Write once. Generate everything."
You shouldn't have to write your validation rules in a Form Request, duplicate them in OpenAPI annotations, and then write them again as TypeScript interfaces for your frontend. Laravel API Contract eliminates this friction. Write clean, standard Laravel code, and let the package do the rest.
π‘ Why This Package Exists
Building APIs usually means maintaining parallel systems. When you update an endpoint in your controller, you also have to update your Postman collection, notify the frontend team to update their types, fix the Swagger annotations, and write the tests.
This causes friction, drift, and broken integrations. We built this package to ensure that your Laravel code is the only source of truth.
π οΈ Problems It Solves
- Documentation Drift: Your OpenAPI/Swagger docs are never out of sync with your code because they are generated from your code.
- Frontend/Backend Friction: Frontend developers get fully typed API clients and TypeScript interfaces automatically.
- Breaking Changes: The built-in contract comparator warns you if you accidentally introduce a breaking change to your API.
- Testing Fatigue: Automatically scaffolds PHPUnit feature tests for every detected endpoint.
β¨ Features
- π§ Zero Annotations Required: Uses static analysis via Reflection and AST parsing. No ugly docblocks or attributes cluttering your controllers.
- β‘ Blazing Fast: Intelligent file caching and optimal Reflection usage ensures it analyzes large APIs in milliseconds.
- π Secure by Default: Hardened against path traversal with strict directory write rules.
- π Intelligent Diffing: Compares versions of your API and outputs detailed breaking-change reports.
- π Framework Native: Integrates seamlessly into the Laravel ecosystem. Feels like a core component.
ποΈ High-Level Architecture Overview
- Route Discovery Engine: Finds all API routes registered in your application.
- Controller Analysis Engine: Inspects your controller methods to determine logic and parameters.
- Form Request & Validation Analyzer: Parses
rules()to determine expected input payloads and validation states. - API Resource Analyzer: Parses your
toArray()methods to determine the exact shape of your JSON responses. - Contract Builder: Merges all analyzed metadata into a single, unified
ApiContractJSON representation. - Generators: Consumes the
ApiContractto emit various artifacts.
π¦ Generated Outputs
Once your application is analyzed, you can generate:
- Swagger/OpenAPI (v3.0): Ready to be served by Swagger UI.
- TypeScript Interfaces: 100% accurate types matching your Form Requests and API Resources.
- Typed API Client (TypeScript): A ready-to-use Axios/Fetch service layer for your frontend.
- Postman Collection (v2.1): Instantly shareable with your team.
- Markdown Documentation: Beautiful, human-readable markdown for static site generators.
- PHPUnit API Tests: Automatically scaffolded feature tests for every route.
- Change Reports: Breaking vs. Non-breaking API change detection over time.
π₯ Installation
Require the package via Composer. It is recommended to install it as a dev dependency unless you are generating contracts in production:
Optionally, publish the configuration file:
π Quick Start
To instantly analyze your API and build the core contract file (usually written to storage/api-contract.json):
Now, you can generate everything else from it!
π» Basic Usage
The package works automatically by inspecting standard Laravel conventions.
Run php artisan api-contract:build, and the package will figure out exactly what /users accepts and what it returns!
π οΈ Available Artisan Commands
| Command | Description |
|---|---|
api-contract:build |
Analyze the application and build the central api-contract.json file. |
api-contract:swagger |
Generate an OpenAPI/Swagger v3.0 JSON specification. |
api-contract:typescript |
Generate TypeScript interface definition files. |
api-contract:client |
Generate a fully-typed TypeScript API client service. |
api-contract:postman |
Generate a Postman v2.1 Collection JSON file. |
api-contract:docs |
Generate human-readable Markdown documentation. |
api-contract:tests |
Generate boilerplate PHPUnit feature tests. |
api-contract:compare |
Compare two contract files and output a breaking-change report. |
π Documentation Index
For deep dives into configuration and advanced generator options, please refer to the documentation:
- Introduction
- Configuration Guide
- Architecture Overview
- Available Commands
- API Contract Definition
- Comparison & Versioning
- Security & Performance
- Extending the Package
- Developer Guide
- FAQ
- Glossary
πΊοΈ Roadmap
- [ ] Support for Data Transfer Objects (DTOs) parsing (Spatie Data).
- [ ] Enum parsing for strict typing in Swagger and TypeScript.
- [ ] Support for generating Nuxt 3/Vue 3 composables.
π€ Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Security Vulnerabilities
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
π License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-api-contract with dependencies
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/container Version ^11.0|^12.0|^13.0
illuminate/filesystem Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/validation Version ^11.0|^12.0|^13.0