Skip to content

Add a PSR-15 middleware, and move the adapters off the container - #80

Merged
DerManoMann merged 1 commit into
mainfrom
feat/adapters
Oct 13, 2026
Merged

DerManoMann merged 1 commit into
mainfrom
feat/adapters

Conversation

@DerManoMann

Copy link
Copy Markdown
Owner

Third part of the new shape for 3.0, and the last change to the adapters' API. Both middleware used to fetch the test case back out of the container under OPENAPI_VERFIER_CONTAINER_KEY, just to call its trait methods. They get an OpenApiVerifier now, and the key is gone.

  • PSR-15: Adapters\Psr15\OpenApiVerifierMiddleware is new, and works with any PSR-15 stack. A mismatch throws OpenApiSchemaMismatchException, and an optional callback runs first, to report it in a way of its own.
  • Slim: the trait registers the PSR-15 middleware, with a callback that fails the test. Adapters\Slim\OpenApiVerifierMiddleware and the probing for a usable container are removed. Since Add OpenApiVerifier, and match paths against the specification's templates #78 matches paths against the specification, the verifier no longer has to be registered before the routing middleware. A new test registers it after routing.
  • Laravel: the middleware takes the verifier and the callback in its constructor. The trait binds that instance under the middleware's class name, and the kernel resolves the same instance for handle() and terminate().

Also in here, since this is the breaking slice: $openapiSpecification gets its real type, object|string|null with a null default, and failSchemaMismatch() builds its message with implode() instead of an eight-placeholder sprintf. Adapters\PSR17Middleware goes, and psr/http-server-middleware is required, interface-only like the other PSR packages.

How a test class uses the adapters does not change: registerOpenApiVerifier() is called the same way. The phpstan baseline drops from 12 entries to 5. What went were findings from the old design, which typed the verifier it fetched as VerifiesOpenApi, a trait, so none of the calls on it could be checked. Checked locally with highest and lowest dependencies.

The Slim adapter registers the new PSR-15 middleware, and the Laravel middleware
gets the verifier through its constructor, so `OPENAPI_VERFIER_CONTAINER_KEY`
is gone. Since paths are matched against the specification, the verifier no
longer has to be registered before Slim's routing middleware.
@DerManoMann
DerManoMann merged commit 73447ae into main Oct 13, 2026
21 checks passed
@DerManoMann
DerManoMann deleted the feat/adapters branch October 13, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant