Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/AGENTS.md export-ignore
/CLAUDE.md export-ignore
/codestyle.php export-ignore
/docker-compose.yml export-ignore
/Makefile export-ignore
12 changes: 6 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ jobs:

strategy:
matrix:
php: [ "8.3", "8.4" ]
php: [ "8.5" ]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 # https://github.com/actions/checkout
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # https://github.com/actions/checkout

- name: Setup PHP
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # 2.31.1 # https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 # https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Cache composer dependencies
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 # https://github.com/actions/cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 # https://github.com/actions/cache
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-php${{ matrix.php }}-composer-

- name: Validate composer.json
run: composer validate
Expand Down
31 changes: 31 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# AGENTS.md

Laravel package `blumilksoftware/openapi-toolbox`: serves OpenAPI documentation UI, builds (merges) specification files, validates them with an Artisan command and validates HTTP requests/responses in tests.

## Commands

Run inside the Docker container (`make run`, then `make shell`) or locally with PHP matching `composer.json`:

- `composer test` - PHPUnit tests (`tests/`, Orchestra Testbench)
- `composer cs` - code style check (php-cs-fixer with `blumilksoftware/codestyle`, config in `codestyle.php`)
- `composer csf` - code style fix

CI (`.github/workflows/check.yml`) runs `composer validate`, `composer cs` and `composer test`.

## Structure

- `src/OpenApiToolboxServiceProvider.php` - registers the `openapi:validate` command, config publishing (tag `openapi-toolbox-config`), routes and views.
- `src/Config/DocumentationConfig.php` - typed accessors over one entry of `openapi_toolbox.documentations`; `Format` enum.
- `src/OpenApiSpecification/SpecificationBuilder.php` - picks one of four builders in `DocumentationBuilders/` (single/multiple files x cached/not cached). Caching lives in the `CacheActions` trait and is invalidated by an md5 checksum of the specification directory.
- `src/OpenApiValidation/` - `openapi:validate` command and validator (checks that files parse and merge).
- `src/OpenApiCompatibility/OpenApiCompatibility.php` - test trait on top of `kirschbaum-development/laravel-openapi-validator`.
- `src/DocumentationUI/` - controller and `UIProvider` enum; views in `resources/views`, routes in `routes/routes.php` (one set per documentation with `ui.enabled`).
- `config/openapi_toolbox.php` - published config; keep it in sync with the config example in `readme.md`.
- `resources/boost/` - guidelines and skill for Laravel Boost, shipped to applications using the package. Update them when public behaviour (config keys, command, trait methods, routes) changes.
- `tests/mocks/` - sample specifications (yml/json, single/multiple files, valid/invalid).

## Conventions

- `declare(strict_types=1);` in every PHP file, double quotes for strings, trailing commas in multiline lists.
- Use constructor property promotion and typed enums for config values.
- Public behaviour changes must be reflected in `readme.md` and `resources/boost/`.
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"homepage": "https://github.com/blumilksoftware/openapi-toolbox",
"license": "MIT",
"require": {
"php": "^8.3",
"illuminate/config": "^12.7.2",
"illuminate/console": "^12.7.2",
"illuminate/http": "^12.7.2",
"illuminate/support": "^12.7.2",
"illuminate/testing": "^12.7.2",
"kirschbaum-development/laravel-openapi-validator": "^1.1.0",
"marcelthole/openapi-merge": "^2.4.0"
"php": "^8.5",
"illuminate/config": "^13.0",
"illuminate/console": "^13.0",
"illuminate/http": "^13.0",
"illuminate/support": "^13.0",
"illuminate/testing": "^13.0",
"kirschbaum-development/laravel-openapi-validator": "^2.0.2",
"marcelthole/openapi-merge": "^2.6.0"
},
"require-dev": {
"blumilksoftware/codestyle": "^4.1.0",
"orchestra/testbench": "^10.2.0",
"phpunit/phpunit": "^12.1.0"
"blumilksoftware/codestyle": "^5.1.1",
"orchestra/testbench": "^11.3.0",
"phpunit/phpunit": "^13.4.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 8 additions & 8 deletions config/openapi_toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
"providers" => [
"elements" => [
"script" => [
"src" => "https://unpkg.com/@stoplight/elements@7.7.16/web-components.min.js",
"sri" => "sha384-bwBnouovwwSJc5fWe7VFNxRg+T2lPHhUcHIzdf7mFfqTZkYtM3T/ehzfEr8F02yY",
"src" => "https://unpkg.com/@stoplight/elements@9.0.29/web-components.min.js",
"sri" => "sha384-enyjBaVmV00WFIo0D7AIVgtZ/4x0idVNWHotG8WUpvQo9HXgMSGAAW2YEOpiJTpP",
],
"stylesheet" => [
"href" => "https://unpkg.com/@stoplight/elements@7.7.16/styles.min.css",
"sri" => "sha384-1lLf7J28IOR7k5RlItk6Y+G3hDgVB3y4RCgWNq6ZSwjYfvJXPtZAdW0uklsAZbGW",
"href" => "https://unpkg.com/@stoplight/elements@9.0.29/styles.min.css",
"sri" => "sha384-iVQBHadsD+eV0M5+ubRCEVXrXEBj+BqcuwjUwPoVJc0Pb1fmrhYSAhL+BFProHdV",
],
],
"swagger" => [
"script" => [
"src" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js",
"sri" => "sha384-xy3YXp34ftsoHshRtcUFjOl/M22B5OEHD5S9AjtVzQokz+BxNff8vNW08msKmH46",
"src" => "https://unpkg.com/swagger-ui-dist@5.34.0/swagger-ui-bundle.js",
"sri" => "sha384-9Td7MKiIr2S83E1kZyyVi8KdJw/S8CpAvu0llLyMeg0xq/hDGiZJfVn0fV4llCmK",
],
"stylesheet" => [
"href" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css",
"sri" => "sha384-pzdBB6iZwPIzBHgXle+9cgvKuMgtWNrBopXkjrWnKCi3m4uJsPPdLQ4IPMqRDirS",
"href" => "https://unpkg.com/swagger-ui-dist@5.34.0/swagger-ui.css",
"sri" => "sha384-4c3vsE5f+trhFyHrFrLM1fFGUn531NIaC7dcqEWIJdoRQJ5CkJbSuSCwXLpaS1KF",
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
php:
image: ghcr.io/blumilksoftware/php:8.4
image: ghcr.io/blumilksoftware/php:8.5
container_name: blumilk-openapi-toolbox-php
working_dir: /application
user: ${CURRENT_UID:-1000}
Expand Down
8 changes: 0 additions & 8 deletions index.php

This file was deleted.

68 changes: 51 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ Install package via Composer and publish configuration file:

```
composer require blumilksoftware/openapi-toolbox
php artisan vendor:publish
php artisan vendor:publish --tag=openapi-toolbox-config
```

If you need it only for internal development (no documentation serving) you can install it with a development flag:

```
composer require blumilksoftware/openapi-toolbox --dev
php artisan vendor:publish
php artisan vendor:publish --tag=openapi-toolbox-config
```

### Configuration

Configuration file should be published into your application after running `php artisan vendor:publish` command. It should look like below:
Configuration file should be published into your application as `config/openapi_toolbox.php` after running `php artisan vendor:publish --tag=openapi-toolbox-config` command. It should look like below:

```php
return [
Expand Down Expand Up @@ -58,22 +58,22 @@ return [
"providers" => [
"elements" => [
"script" => [
"src" => "https://unpkg.com/@stoplight/elements@7.7.16/web-components.min.js",
"sri" => "sha384-bwBnouovwwSJc5fWe7VFNxRg+T2lPHhUcHIzdf7mFfqTZkYtM3T/ehzfEr8F02yY",
"src" => "https://unpkg.com/@stoplight/elements@9.0.29/web-components.min.js",
"sri" => "sha384-enyjBaVmV00WFIo0D7AIVgtZ/4x0idVNWHotG8WUpvQo9HXgMSGAAW2YEOpiJTpP",
],
"stylesheet" => [
"href" => "https://unpkg.com/@stoplight/elements@7.7.16/styles.min.css",
"sri" => "sha384-1lLf7J28IOR7k5RlItk6Y+G3hDgVB3y4RCgWNq6ZSwjYfvJXPtZAdW0uklsAZbGW",
"href" => "https://unpkg.com/@stoplight/elements@9.0.29/styles.min.css",
"sri" => "sha384-iVQBHadsD+eV0M5+ubRCEVXrXEBj+BqcuwjUwPoVJc0Pb1fmrhYSAhL+BFProHdV",
],
],
"swagger" => [
"script" => [
"src" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js",
"sri" => "sha384-xy3YXp34ftsoHshRtcUFjOl/M22B5OEHD5S9AjtVzQokz+BxNff8vNW08msKmH46",
"src" => "https://unpkg.com/swagger-ui-dist@5.34.0/swagger-ui-bundle.js",
"sri" => "sha384-9Td7MKiIr2S83E1kZyyVi8KdJw/S8CpAvu0llLyMeg0xq/hDGiZJfVn0fV4llCmK",
],
"stylesheet" => [
"href" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css",
"sri" => "sha384-pzdBB6iZwPIzBHgXle+9cgvKuMgtWNrBopXkjrWnKCi3m4uJsPPdLQ4IPMqRDirS",
"href" => "https://unpkg.com/swagger-ui-dist@5.34.0/swagger-ui.css",
"sri" => "sha384-4c3vsE5f+trhFyHrFrLM1fFGUn531NIaC7dcqEWIJdoRQJ5CkJbSuSCwXLpaS1KF",
],
],
],
Expand All @@ -84,11 +84,13 @@ return [

#### Multiple documentations

You can create more than one documentation by adding element to `openapi_toolbox.documentations` array.
You can create more than one documentation by adding element to `openapi_toolbox.documentations` array. Make sure every documentation has its own `ui.routing.prefix`, `ui.routing.name` and `cache.key`.

```php

return {
"documentations" => [
"openapi" => [
// ...
],
"test" => [
"format" => Format::YmlToJson,
"specification" => [
Expand All @@ -99,7 +101,7 @@ return {
"cache" => [
"enabled" => false,
"driver" => "default",
"key" => "openapi",
"key" => "openapi.test",
],
"ui" => [
"enabled" => false,
Expand All @@ -113,7 +115,7 @@ return {
"provider" => UIProvider::Elements,
],
],
}
],
```

#### OpenAPI documentation UI
Expand All @@ -133,9 +135,11 @@ Serving a documentation itself can be tricky, especially if specification is bui
OpenAPI specification files will be built accordingly to configuration and validated on demand by running an Artisan command:

```
php artisan openapi:validate {documentation}
php artisan openapi:validate {documentation?}
```

The `documentation` argument is optional; the `openapi_toolbox.default` documentation is validated when it is omitted.

Good example of usage would be adding this command to CI pipeline for opened pull requests.

#### Testing requests and responses against OpenAPI specification
Expand All @@ -152,3 +156,33 @@ Every time any HTTP call to application would be performed during tests, additio

With configuration `cache.enabled = true` internal builders will use cached OpenAPI specifications.
You can change the cache store by setting the `cache.driver` option, for example: `cache.driver = redis`. Make sure to use one of the cache drivers available in your Laravel application.

### AI assistants

The package ships guidelines and a skill for [Laravel Boost](https://github.com/laravel/boost) in `resources/boost`. If your application uses Boost, run `php artisan boost:install` (or `php artisan boost:update` when Boost is already installed) and select this package. Your AI agent will then know how to edit the specification, validate it and write tests against it without analysing the package source.

Without Boost, point your agent to these files manually. Both are plain Markdown (despite the `.blade.php` extension of the guidelines file):

- `resources/boost/guidelines/core.blade.php` - short rules worth keeping always in the agent's context,
- `resources/boost/skills/openapi-toolbox/SKILL.md` - step-by-step recipes loaded on demand.

For Claude Code, import the guidelines and reference the skill in your application's `CLAUDE.md`:

```markdown
@vendor/blumilksoftware/openapi-toolbox/resources/boost/guidelines/core.blade.php

Before working with OpenAPI specification read vendor/blumilksoftware/openapi-toolbox/resources/boost/skills/openapi-toolbox/SKILL.md
```

For other agents (Cursor, Codex etc.) add the same reference to `AGENTS.md`:

```markdown
Before working with OpenAPI specification read vendor/blumilksoftware/openapi-toolbox/resources/boost/guidelines/core.blade.php and vendor/blumilksoftware/openapi-toolbox/resources/boost/skills/openapi-toolbox/SKILL.md
```

Both variants stay up to date with `composer update`. Alternatively, copy the skill into your project to make it a native Claude Code skill (remember to copy it again after updating the package):

```
mkdir -p .claude/skills/openapi-toolbox
cp vendor/blumilksoftware/openapi-toolbox/resources/boost/skills/openapi-toolbox/SKILL.md .claude/skills/openapi-toolbox/
```
16 changes: 16 additions & 0 deletions resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## blumilksoftware/openapi-toolbox

This application keeps its OpenAPI specification as files and uses `blumilksoftware/openapi-toolbox` to serve, validate and test against it. The specification is the contract: change it first, then the code.

### Where things are
- Configuration: `config/openapi_toolbox.php`. Documentations are defined under `documentations`, the default one is named by `default` (usually `openapi`).
- Specification files: `specification.path` + `specification.index` of a documentation (by default `resource_path("openapi")` and `openapi.yml`).
- With `specification.allow_multiple_files = true` the index file references sibling files via `$ref` (e.g. `"/ping": { "$ref": ping.yml }`). Only files placed directly in `specification.path` (no subdirectories) with the extension matching `format` are merged (`.yml` for `Format::Yml` and `Format::YmlToJson`, `.yaml` for `Format::Yaml`, `.json` for `Format::Json`).

### Rules
- After every change in specification files run `php artisan openapi:validate` (or `php artisan openapi:validate <documentation>` for a non-default one). It checks that the files parse and merge; it does not replace request/response validation in tests.
- Feature tests that hit HTTP endpoints should use the `Blumilk\OpenApiToolbox\OpenApiCompatibility\OpenApiCompatibility` trait. Every request and response made in such a test is validated against the specification, so an undocumented endpoint, field or status code fails the test.
- When a test intentionally sends an invalid request or expects an undocumented response, call `$this->withoutRequestValidation()` and/or `$this->withoutResponseValidation()` before the request. Do not disable validation just to make a test pass; fix the specification or the code instead.
- To test against a documentation other than the default one, override `getDocumentationName(): string` in the test case.
- When `ui.enabled = true`, the UI is served at `GET /{ui.routing.prefix}` and the built specification at `GET /{ui.routing.prefix}/raw` (route names `{ui.routing.name}` and `{ui.routing.name}.raw`).
- When `cache.enabled = true`, the built specification is cached and invalidated automatically by a checksum of files in `specification.path`; no manual cache clearing is needed after editing the specification.
Loading