PHPackages                             psx/openapi - 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. psx/openapi

ActiveLibrary[API Development](/categories/api)

psx/openapi
===========

Model classes to generate an OpenAPI specification in a type-safe way

v1.1.0(5mo ago)286.6k↑30.6%3Apache-2.0PHPPHP &gt;=8.1CI passing

Since Apr 7Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/apioo/psx-openapi)[ Packagist](https://packagist.org/packages/psx/openapi)[ Docs](https://phpsx.org)[ Fund](https://www.paypal.me/fusioapi)[ GitHub Sponsors](https://github.com/chriskapp)[ RSS](/packages/psx-openapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (7)Used By (3)

OpenAPI
=======

[](#openapi)

This library contains model classes to generate an OpenAPI specification in a type-safe way. The models are automatically generated based on the [TypeSchema](https://typeschema.org/) specification (s. `./spec/typeschema.json`). The following example shows how you can generate an OpenAPI spec:

```
$info = new Info();
$info->setVersion('1.0.0');
$info->setTitle('Swagger Petstore');

$parameter = new Parameter();
$parameter->setName('limit');
$parameter->setIn('query');
$parameter->setDescription('How many items to return at one time (max 100)');
$parameter->setRequired(false);
$parameter->setSchema(Record::fromArray(['type' => 'integer', 'format' => 'int32']));

$mediaType = new MediaType();
$mediaType->setSchema(Record::fromArray(['$ref' => '#/components/schemas/Pets']));

$content = new MediaTypes();
$content->put('application/json', $mediaType);

$response = new Response();
$response->setDescription('An paged array of pets');
$response->setContent($content);

$responses = new Responses();
$responses->put('200', $response);

$operation = new Operation();
$operation->setSummary('List all pets');
$operation->setOperationId('listPets');
$operation->setTags(['pets']);
$operation->setParameters([$parameter]);
$operation->setResponses($responses);

$pathItem = new PathItem();
$pathItem->setGet($operation);

$paths = new Paths();
$paths->put('/pets', $pathItem);

$schemas = new Schemas();
$schemas->put('Pet', [
    'required' => ['id', 'name'],
    'properties' => [
        'id' => ['type' => 'integer', 'format' => 'int64'],
        'name' => ['type' => 'string'],
        'tag' => ['type' => 'string'],
    ]
]);

$schemas->put('Pets', [
    'type' => 'array',
    'items' => ['$ref' => '#/components/schemas/Pet'],
]);

$components = new Components();
$components->setSchemas($schemas);

$openAPI = new OpenAPI();
$openAPI->setInfo($info);
$openAPI->setPaths($paths);
$openAPI->setComponents($components);

echo json_encode($openAPI, JSON_PRETTY_PRINT);
```

This would result in the following JSON:

```
{
  "openapi": "3.0.3",
  "info": {
    "title": "Swagger Petstore",
    "version": "1.0.0"
  },
  "paths": {
    "\/pets": {
      "get": {
        "tags": [
          "pets"
        ],
        "summary": "List all pets",
        "operationId": "listPets",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "An paged array of pets",
            "content": {
              "application\/json": {
                "schema": {
                  "$ref": "#\/components\/schemas\/Pets"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pet": {
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          }
        }
      },
      "Pets": {
        "type": "array",
        "items": {
          "$ref": "#\/components\/schemas\/Pet"
        }
      }
    }
  }
}
```

Contribution
------------

[](#contribution)

If you want to suggest changes please only change the `typeschema.json` specification and then run the `php gen.php` script to regenerate all model classes.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance72

Regular maintenance activity

Popularity33

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

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

Every ~196 days

Recently: every ~245 days

Total

6

Last Release

156d ago

Major Versions

v0.1.2 → v1.0.02024-10-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2505846?v=4)[Christoph Kappestein](/maintainers/chriskapp)[@chriskapp](https://github.com/chriskapp)

---

Top Contributors

[![chriskapp](https://avatars.githubusercontent.com/u/2505846?v=4)](https://github.com/chriskapp "chriskapp (17 commits)")

---

Tags

openapimodeldto

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[swagger-api/swagger-ui

 Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

28.8k45.4M99](/packages/swagger-api-swagger-ui)[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k7.8M57](/packages/dedoc-scramble)[cebe/php-openapi

Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.

49815.4M86](/packages/cebe-php-openapi)[jolicode/slack-php-api

An up to date PHP client for Slack's API

2534.4M12](/packages/jolicode-slack-php-api)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)

PHPackages © 2026

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