A universal OpenAPI (Swagger) schema parser 2022-03-30 16:48 UTC

This package is auto-updated.

Last update: 2024-04-29 03:44:49 UTC


Latest Stable Version Total Downloads License codecov

A universal OpenAPI (V3) or Swagger (V2) schema parser to convert OpenAPI/Swagger files into PHP object for programming use.


composer require-dev allansun/openapi-parser


This project is used for 'dev' environment only. It does not generate/provide any codes for run-time environment.

To start


    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.


    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


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

The result would be:



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


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


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


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