Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 2.38 KB

File metadata and controls

54 lines (37 loc) · 2.38 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Overview

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.

Architecture

The codebase consists of two main components:

Core Classes

  • 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(), and apiMap() methods

Key Dependencies

The library integrates several components:

  • league/openapi-psr7-validator for OpenAPI validation
  • nyholm/psr7 for PSR-7 HTTP message factories
  • symfony/psr-http-message-bridge to convert Symfony HTTP messages to PSR-7
  • symfony/yaml for parsing OpenAPI YAML specifications

Path Mapping System

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.

Usage Pattern

  1. Create an OpenApiValidator instance with the path to your OpenAPI spec and path mappings
  2. Use the trait in PHPUnit tests by implementing the required abstract methods
  3. The trait automatically generates test cases for all endpoints defined in the OpenAPI spec
  4. Each endpoint is tested with both full parameters (from examples/defaults) and minimal parameters

Development Notes

  • 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