项目作者: swaggest

项目描述 :
OpenAPI 3.0 / Swagger 2.0 schema PHP mappings
高级语言: PHP
项目地址: git://github.com/swaggest/php-swagger2-schema.git
创建时间: 2018-01-02T09:52:55Z
项目社区:https://github.com/swaggest/php-swagger2-schema

开源协议:

下载


OpenAPI 3.0 and Swagger 2.0 schema PHP mappings

Build Status
codecov

Access and validate OpenAPI 3.0 and Swagger 2.0 schemas from PHP.

Installation

  1. composer require swaggest/swagger2-schema

Usage

OpenAPI 3.0

  1. // Load schema
  2. $json = json_decode(file_get_contents(__DIR__ . '/../../../spec/petstore-openapi3.json'));
  3. // Import and validate
  4. $schema = OpenAPI3Schema::import($json);
  5. // Access data through PHP classes
  6. $this->assertSame('Swagger Petstore', $schema->info->title);
  7. $ops = $schema->paths['/pets']->getGetPutPostDeleteOptionsHeadPatchTraceValues();
  8. $this->assertSame('List all pets', $ops['get']->summary);
  9. $responseSchema = $ops['get']->responses[200]->content['application/json']->schema;
  10. $this->assertSame('array', $responseSchema->type);

Swagger 2.0

  1. // Load schema
  2. $json = json_decode(file_get_contents(__DIR__ . '/../../spec/petstore-swagger.json'));
  3. // Import and validate
  4. $schema = SwaggerSchema::import($json);
  5. // Access data through PHP classes
  6. $this->assertSame('Swagger Petstore', $schema->info->title);