Access and validate OpenAPI 3.0
and Swagger 2.0
schemas from PHP.
composer require swaggest/swagger2-schema
// Load schema
$json = json_decode(file_get_contents(__DIR__ . '/../../../spec/petstore-openapi3.json'));
// Import and validate
$schema = OpenAPI3Schema::import($json);
// Access data through PHP classes
$this->assertSame('Swagger Petstore', $schema->info->title);
$ops = $schema->paths['/pets']->getGetPutPostDeleteOptionsHeadPatchTraceValues();
$this->assertSame('List all pets', $ops['get']->summary);
$responseSchema = $ops['get']->responses[200]->content['application/json']->schema;
$this->assertSame('array', $responseSchema->type);
// Load schema
$json = json_decode(file_get_contents(__DIR__ . '/../../spec/petstore-swagger.json'));
// Import and validate
$schema = SwaggerSchema::import($json);
// Access data through PHP classes
$this->assertSame('Swagger Petstore', $schema->info->title);