Core Principle: Single Source of Truth (SSOT)
In Apivalk, your PHP code is the single source of truth. By defining the structure and validation rules of your requests and responses once, you gain:- Automated Validation: Requests are validated against the documentation before reaching your controller.
- Type Safety: Input data is automatically cast to the correct PHP types.
- IDE Support: DocBlocks are generated to provide autocompletion for request parameters.
- OpenAPI Specification: A full OpenAPI 3.0 (Swagger) JSON is generated automatically.
- Reusable Components: Standard response objects can be reused across multiple endpoints.
The Documentation Flow
- Define: You implement
getRequestDocumentation()andgetResponseDocumentation()in your controllers using the Property System. - Generate DocBlocks: Use the
DocBlockGeneratorto create “Shape” classes and update your request classes with@propertytags. - Run & Validate: The
RequestValidationMiddlewareuses your definitions to validate incoming data. - Export: The
OpenAPIGeneratorcrawls your routes and documentation to produce a Swagger file.
Key Subsystems
- Request Documentation: Defining endpoint input contracts.
- Response Documentation: Defining endpoint output contracts.
- Property Collections: Property Collections in Apivalk are used to group multiple properties together.
- Property System: The building blocks for defining data types and validation rules.
- DocBlock Generator: Enhances the developer experience with IDE support.
- OpenAPI Generator: Converts your code-based documentation into a standard format, including automatic security scheme discovery.
- Response Objects: Pre-defined reusable objects for common API responses.