swaggest / swagger2-schema
Swagger 2.0 schema PHP mappings
Installs: 2 252
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- ext-json: *
- swaggest/json-schema: ^0.12.35
Requires (Dev)
- phpunit/phpunit: ^5
- swaggest/php-code-builder: ^0.2.28
README
Access and validate OpenAPI 3.0
and Swagger 2.0
schemas from PHP.
Installation
composer require swaggest/swagger2-schema
Usage
OpenAPI 3.0
// 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);
Swagger 2.0
// 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);