This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a PHP library that provides OpenAPI validation for Symfony applications. The library validates both HTTP requests and responses against OpenAPI specifications using PSR-7 HTTP message interfaces.
The codebase consists of two main components:
-
OpenApiValidator(src/OpenApiValidator.php:1): The main validator class that handles validation logic- Parses OpenAPI YAML specifications
- Converts Symfony requests/responses to PSR-7 format
- Validates requests and responses against the spec
- Generates test cases from OpenAPI specifications
-
OpenApiValidationTrait(src/OpenApiValidationTrait.php:1): PHPUnit test trait for integration testing- Provides a ready-to-use test method for endpoint validation
- Automatically generates test cases from OpenAPI spec using data providers
- Requires implementing classes to provide
client(),openApiPath(), andapiMap()methods
The library integrates several components:
league/openapi-psr7-validatorfor OpenAPI validationnyholm/psr7for PSR-7 HTTP message factoriessymfony/psr-http-message-bridgeto convert Symfony HTTP messages to PSR-7symfony/yamlfor parsing OpenAPI YAML specifications
The validator uses a path mapping system ($pathMappings in constructor) to translate between:
- OpenAPI specification paths (e.g.,
/api/users/{id}) - Actual application paths (e.g.,
/users/{id})
This allows the library to work with applications where the actual route structure differs from the OpenAPI specification.
- Create an
OpenApiValidatorinstance with the path to your OpenAPI spec and path mappings - Use the trait in PHPUnit tests by implementing the required abstract methods
- The trait automatically generates test cases for all endpoints defined in the OpenAPI spec
- Each endpoint is tested with both full parameters (from examples/defaults) and minimal parameters
- This is a library package (no application-specific build/test commands)
- No composer.json found - likely managed by a parent project
- Uses PHP 8+ features like
declare(strict_types=1)and constructor property promotion - Follows PSR-12 coding standards with proper type declarations