swaggest / swagger2-schema
Swagger 2.0 规范 PHP 映射
v0.2.6
2021-06-17 22:37 UTC
Requires
- ext-json: *
- swaggest/json-schema: ^0.12.35
Requires (Dev)
- phpunit/phpunit: ^5
- swaggest/php-code-builder: ^0.2.28
README
使用 PHP 访问和验证 OpenAPI 3.0 和 Swagger 2.0 规范。
安装
composer require swaggest/swagger2-schema
用法
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);