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

ActiveLibrary[API Development](/categories/api)

reinfi/openapi-models
=====================

Generate PHP models from openapi definition

v1.9.6(3mo ago)85.8k↓29.2%2[1 PRs](https://github.com/reinfi/openapi-models/pulls)MITPHPPHP ~8.3.0 || ~8.4.0CI passing

Since Dec 24Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/reinfi/openapi-models)[ Packagist](https://packagist.org/packages/reinfi/openapi-models)[ RSS](/packages/reinfi-openapi-models/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (62)Used By (0)

OpenAPI Models generated for PHP
================================

[](#openapi-models-generated-for-php)

This library does not provide any client or server implementation for your open api definition. It just generates models defined in your schemas.

This library may not be feature complete for all openapi definition. If you miss a feature, just file an issue.

Why?
----

[](#why)

There are some common open api generators like [JanePHP](https://github.com/janephp/janephp) or [OpenAPI Generator](https://openapi-generator.tech) but they create old PHP Syntax due to their backwards compatibility.

- No readonly objects
- No constructor promoted properties
- No typed properties, except PHPDoc

That is the reason why this library exists to simply generate models with new PHP syntax.

Install
-------

[](#install)

Use composer to install it as development dependency.

`composer require --dev reinfi/openapi-models`

Usage
-----

[](#usage)

Default configuration file is `openapi-models.php`.

Your configuration file should return an array with the following settings:

```
return [
    'paths' => [__DIR__ . '/spec'], # array of path to check for openapi files
    'outputPath' => __DIR__ . '/output', # output directory
    'namespace' => 'Api', # namespace for generated classes, can be empty
    'clearOutputDirectory' => true, # to remove all files in output directory, default is false
    'dateTimeAsObject' => false, # date/date-time definition will be `string` otherwise `DateTimeInterface`.
    'dateTimeFormat' => 'Y-m-d H:i:s', # format for serialize of date time fields
];
```

### Generate

[](#generate)

To generate your files just run `php vendor/bin/openapi-models generate`.

If you like to store your configuration somewhere else you need to provide the file name to the command.

`php vendor/bin/openapi-models generate --config spec/openapi-models.php`

### Validate

[](#validate)

To validate your files, i.e. if the specification matches the generated files, you can run `php vendor/bin/openapi-models validate`.

Make sure you use the same configuration file as used for the generate command.

Namespace
---------

[](#namespace)

You can specify a custom namespace for a schema, response or request-body using the `x-php-namespace` extension. This allows you to extend the default namespace configuration.

```
components:
  schemas:
    Foo:
      x-php-namespace: Bar
      type: object
      required:
        - id
      properties:
        id:
          type: number
```

Types
-----

[](#types)

This library does not support `mixed` type from open-api specification. Therefore, you always have to set a type in your specification.

Enum
----

[](#enum)

Enums are converted to native PHP enums. If your property should be nullable you must set the property itself nullable and also add null as enum case value.

```
components:
  schemas:
    Test1:
      type: object
      required:
        - state
      properties:
        state:
          type: string
          nullable: true
          enum:
            - Good
            - Bad
            - null
```

For more information about nullable enums, see the [Swagger documentation](https://swagger.io/docs/specification/v3_0/data-models/enums/#nullable-enums).

Date or DateTime
----------------

[](#date-or-datetime)

The following schema has date/date-time properties.

```
components:
  schemas:
    Test1:
      type: object
      required:
        - date
      properties:
        date:
          type: string
          format: date
        dateTime:
          type: string
          format: date-time
```

The default is to generate the fields as `string`-type because this would not require any logic for serialization of the class.

You can change the configuration `dateTimeAsObject` to `true` and then these fields will be of type `DateTimeInterface`.

A serialization function is added to these classes to support native `json_encode`. If you do not use native json\_encode you may need to provide an own implementation to fulfill open api specifications.

The default format for a `date` is `Y-m-d`, for a `date-time`-type is `Y-m-d\TH:i:sP` (RFC3339), but you can configure it.

```
'dateFormat' => 'Y-m-d',
'dateTimeFormat' => 'Y-m-d H:i:s',
```

This is just for convenience if you do not want to deal with time zones or just need different formats.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance79

Regular maintenance activity

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% 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 ~21 days

Recently: every ~50 days

Total

37

Last Release

111d ago

Major Versions

v0.7.0 → v1.0.02024-02-18

PHP version history (2 changes)v0.1.0PHP &gt;= 8.2

v1.5.0PHP ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd12a82b28a65cedc8e06642dabfbfd70fd512287bbaed49aaac0072fe898e41?d=identicon)[reinfi](/maintainers/reinfi)

---

Top Contributors

[![reinfi](https://avatars.githubusercontent.com/u/9324423?v=4)](https://github.com/reinfi "reinfi (223 commits)")[![voxpelli](https://avatars.githubusercontent.com/u/34457?v=4)](https://github.com/voxpelli "voxpelli (19 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[spawnia/sailor

A typesafe GraphQL client for PHP

92505.0k2](/packages/spawnia-sailor)[marcelthole/openapi-merge

Merge multiple OpenAPI YML/JSON files into one

1886.4k4](/packages/marcelthole-openapi-merge)[litalico-engineering/eg-r2

Easy request validation and route generation from open API specifications (for Laravel)

1112.5k](/packages/litalico-engineering-eg-r2)

PHPackages © 2026

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