PHPackages                             googoogajoob/openapi-slim4 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. googoogajoob/openapi-slim4

ActiveLibrary[API Development](/categories/api)

googoogajoob/openapi-slim4
==========================

Bringing Slim4 and OpenApi together

1.0.0(3y ago)452PHPPHP ^8.0 || ^8.1 || ^8.2

Since Jun 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/googoogajoob/openapi-slim4)[ Packagist](https://packagist.org/packages/googoogajoob/openapi-slim4)[ RSS](/packages/googoogajoob-openapi-slim4/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Purpose
=======

[](#purpose)

Configure the paths of a slim4 application from an **openapi** definition.

[![Total Downloads](https://camo.githubusercontent.com/9334f37bf51b7476f861c5ea51c8f3252d368838b400e1a52a4f5a11d5380bbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f6e6f6c6f672f6d6f6e6f6c6f672e737667)](https://packagist.org/packages/googoogajoob/openapi-slim4)

Installation
============

[](#installation)

- composer require googoogajoob/openapi-slim4

Requirements
============

[](#requirements)

- Php 8.0
- Slim4
- An OpenApi Definition (yaml or json)

Usage
=====

[](#usage)

There are many examples of how one can configure the routes of a slim4 application. One such [skeleton project](https://github.com/slimphp/Slim-Skeleton) uses [index.php](https://github.com/slimphp/Slim-Skeleton/blob/master/public/index.php) and [routes.php](https://github.com/slimphp/Slim-Skeleton/blob/master/app/routes.php) to accomplish this.

The test cases for openapi-slim4 have adapted this in [index.php](./tests/docker-test-environment/public/index.php) where openapi-slim4 replaces the need to call *routes.php*.

The critical section is

```
/* BEGIN ROUTE AND MIDDLEWARE CONFIGURATION
When using OpenApiSlim4, only the ELSE branch would be needed */
if ($container->get('nativeSlimConfiguration')) {
    require __DIR__ . '/../config/nativeSlimConfiguration.php';
    slim4ConfigureRoutes($app);
#    slim4ConfigureGroupMiddleware($app);  // Future Development
    slim4ConfigureGlobalMiddleware($app);
} else {
    $openApiConfigurator = new OpenApiSlim4($container->get('openApiPath'), $app, $logger, $throwExceptionOnInvalid);
    if (!$openApiConfigurator->configureFramework()) {
        throw new Exception($openApiConfigurator->getValidationMessagesString());
    }
}
/* END ROUTE AND MIDDLEWARE CONFIGURATION */
```

Assuming all the variables have been correctly defined the absolute minimum would be the 2 lines

```
$openApiConfigurator = new OpenApiSlim4($container->get('openApiPath'), $app, $logger, $throwExceptionOnInvalid);
$openApiConfigurator->configureFramework();
```

If problems occur, please review the tests

Description
===========

[](#description)

Preface
-------

[](#preface)

```
With REST-API definitions there is a difference of opinion about terminology.
In particular with the terms PATH and ROUTE.

For example when referencing the REST-API endpoint GET /user/data/{id}
* Slim4 refers to "/user/data" as a ROUTE
* Openapi refers to "/user/data" as a PATH

The documentation in this project uses the two terms interchangeably

```

Concept
-------

[](#concept)

openapi-slim4 is a tool that can read an openapi specification and dynamically configure a slim4 application accordingly. This includes endpoint handlers as well as middleware. openapi-slim4 will typically be called in the *index.php* entry point of an application and dynamically configure slim4 upon every request. This effectively eliminates the need to configure the restapi endpoints via other php code such as *routes.php* for example.

Thus, when an openapi definition changes, the route specifications of the slim4 application will automatically be adjusted. Depending on how trivial the changes to the specification are, this may or may not have larger consequences for the handler and middleware codebase.

In essence openapi-slim4 performs the following:

- Openapi endpoint definitions are mapped to handlers
- Global middleware defined in openapi is configured as global middleware in slim4
- Configuring PATH middleware is planned for future development

*An openapi definition does not allow for the specification of middleware. However, openapi-slim4 implements an extension to the standard openapi syntax which allows for this.*

### The 'source-of-truth' argument

[](#the-source-of-truth-argument)

In discussions surrounding the implementation of openapi in the development of restapis, the *source-of-truth* argument often comes into play. Central to this discussion is the question, "what role does the openapi definition play in the larger software architecture? Is it simply a means of documentation or is it the controlling instance of how a restapi service actually operates?"

#### Documentation Only

[](#documentation-only)

This viewpoint sees an openapi specification simply as a means of documentation. The actual 'source of truth' is the code that creates the restapi service (a php slim4 application or any number of other possibilities). In such scenarios there are many generators available which can dynamically create an openapi documentation from a specific codebase. This may be the best option for smaller development teams, where only a few clients are dependent on the restapi service and communication between developers is uncomplicated.

#### Controlling instance

[](#controlling-instance)

This viewpoint sees an openapi specification not only as documentation but also as the document which ultimately defines how a restapi service WILL actually operate. The openapi specification is not only documentation but also a configuration file. In this sense the openapi definition is a kind of contract, to which all participants MUST conform. This may make more sense for larger development teams. A smaller architectural team creates the definition and all developers hold to it, thus reducing the need for communication among developers.

> openapi-slim4 was conceived to support the 'controlling instance' type of operation

Specific Capabilities
---------------------

[](#specific-capabilities)

- HTTP-Method Handlers
- Path Middleware (Future development)
- Global Middleware

Behavior
--------

[](#behavior)

- Paths and Middleware will be set in accordance with the Openapi definition (see table below)
- Optional logging via a *Psr\\Log\\LoggerInterface*
- Optionally throw an Exception upon validation failure

Openapi - Slim4 Mapping
-----------------------

[](#openapi---slim4-mapping)

The parameters necessary for configuring Slim4 are derived from the Openapi definition. The Slim4-method for performing the configuration has three parameters. This table shows where they are taken from in the openapi definition.

```
RouteCollectorProxy::map(array $methods, string $pattern, $callable): RouteInterface
```

Openapi ParameterSlim4 ParameterRemarkspaths.&lt;path&gt;.&lt;operation&gt;$methodsOne HTTP Methodpaths.&lt;path&gt;$patternThe URL Path/Routepaths.&lt;path&gt;.&lt;operation&gt;.operationId$callableThe PHP callable can have two forms &lt;class&gt;:method or &lt;class&gt;
- In the first case the separator ":" and **NOT** "::" is expected
- In the second case the method *\_\_invoke()* is expected to be a member of the classParameter Definitions and Dependency Injection Options
------------------------------------------------------

[](#parameter-definitions-and-dependency-injection-options)

The following table summarizes, the possibilities of supplying the settings for the **openapi-slim4** object

ConstructorSetterEnvironment VariableRequiredDefaultRemarksOpenapi Definition✅✅
OpenApiSlim4::setOpenApi**OPENAPI\_PATH**
*Filename only*✅NoneThe Openapi definition can be specified as an object of cebe/php-openapi/src/Reader or a filename (JSON, YAML, YML)Slim4 App✅✅
OpenApiSlim4::setSlimApplication❌✅NoneSet the Slim4 **app** ObjectLogging✅✅❌❌False - no loggingEnvironment Variable Flag. Default false (no logging)Throw Validation Exception✅✅❌❌False - exceptions not thrownEnvironment Variable Flag. Default false (no exception)Development and Testing
=======================

[](#development-and-testing)

For testing details see [tests/README.md](./tests/README.md)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1107d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6421745?v=4)[Andrew Potter](/maintainers/googoogajoob)[@googoogajoob](https://github.com/googoogajoob)

---

Top Contributors

[![googoogajoob](https://avatars.githubusercontent.com/u/6421745?v=4)](https://github.com/googoogajoob "googoogajoob (151 commits)")

### Embed Badge

![Health badge](/badges/googoogajoob-openapi-slim4/health.svg)

```
[![Health](https://phpackages.com/badges/googoogajoob-openapi-slim4/health.svg)](https://phpackages.com/packages/googoogajoob-openapi-slim4)
```

###  Alternatives

[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.1k](/packages/showdoc-showdoc)[oat-sa/tao-core

TAO core extension

66143.7k124](/packages/oat-sa-tao-core)[brandembassy/slim-nette-extension

19201.2k](/packages/brandembassy-slim-nette-extension)[dsuurlant/response2schema

Generate an OpenAPI schema definition for an object based on a JSON response.

9158.5k](/packages/dsuurlant-response2schema)[canvural/php-openapi-faker

Library to generate fake data for OpenAPI request/response/schemas.

92405.4k2](/packages/canvural-php-openapi-faker)[b13/slimphp-bridge

Provides a middleware for registering Slim PHP applications within TYPO3 Frontend Sites

2049.5k1](/packages/b13-slimphp-bridge)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
