2017 © Pedro Peláez
 

library swagger2-schema

Swagger 2.0 schema PHP mappings

image

swaggest/swagger2-schema

Swagger 2.0 schema PHP mappings

  • Thursday, March 22, 2018
  • by vearutop
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

OpenAPI 3.0 and Swagger 2.0 schema PHP mappings

Build Status codecov, (*1)

Access and validate OpenAPI 3.0 and Swagger 2.0 schemas from PHP., (*2)

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);

The Versions