allansun/openapi-parser

A universal OpenAPI (Swagger) schema parser

Maintainers

👁 allansun

Package info

github.com/allansun/openapi-parser

pkg:composer/allansun/openapi-parser

Statistics

Installs: 13 015

Dependents: 92

Suggesters: 0

Stars: 11

Open Issues: 5

2.2 2024-09-22 12:38 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 8cfc73372f7ff6921a0e429d4812371425979c2f

  • Allan Sun <allan.sun.woop@bricre.com>

This package is auto-updated.

Last update: 2026-06-22 17:42:29 UTC


README

👁 Latest Stable Version
👁 Total Downloads
👁 License
👁 codecov

A universal OpenAPI (V3) and Swagger (V2) schema parser that converts OpenAPI/Swagger files into PHP objects for programming use.

Installing

composer require-dev allansun/openapi-parser

Usage

This project is intended for development environments only. It does not generate or provide any code for runtime environments. To start

<?php

 use OpenAPI\Parser;
 
 $OpenAPI = Parser::parse('openapi.json');

The parser class will automatically detect input file type (JSON or YAML) and use correct parser (Swagger or OpenAPI) to parse the input.

Alternatively, you can call the correct parser directly.

<?php

 use OpenAPI\Parser\OpenAPIParser;
 
 $Parser = new OpenAPIParser();
 
 $OpenAPI = $Parser->parse(json_decode(file_get_contents('openapi.json'), true));

Or to parse the legacy Swagger version

<?php

 use OpenAPI\Parser\SwaggerParser;
 
 $Parser = new SwaggerParser();
 
 $Swagger = $Parser->parse(json_decode(file_get_contents('swagger.json'), true));

The result would be:

👁 OpenAPI

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details