Skip to content

Commit

Permalink
Merge pull request zircote#1 from zircote/3.x
Browse files Browse the repository at this point in the history
Migrate all examples to OpenAPI (zircote#488)
  • Loading branch information
sonrac authored Jun 5, 2018
2 parents 059f707 + 85d2a3b commit d5a2db7
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 97 deletions.
74 changes: 1 addition & 73 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
# Changelog

## 2.0.11

- Implemented Swagger->ref(). $swagger->ref('#/info/contact') === $swagger->info->contact
- Added validation of internal refs.
- Misc typos and improved unittests #399, #402

## 2.0.10

- Fix errors when parsing php7 anonymous class #380, #390
- Added support for linked files and directories #393
- Added support for $ref in deserialize() #369
- Misc documentation tweaks.

## 2.0.9

- Added support for PHP 7.1 and dropped support for PHP 5.5 and below
- Added `composer test` script
- Added support for custom DocParser->setImports() #360

## 2.0.8

- Dynamic Definitions / partial support #301
- By default only scan *.php files #350
- Removed silence operator @, improves compatiblity custom errorhandlers #331
- Additional datetime classes & interfaces #338
- Fixed case of UNDEFINED constants namespaces, improves hhvm compatibility #319
- Misc improvements to the docs

## 2.0.7

- Beter validation of type="file" #305
- Augment Operations summary and description based on the comment. #293
- Bugfixes #300
- Add support for xml (and externalDocs and properties) inside a @SWG\Items. #279
- Nested properties are no longer injected into the Definition #297
- Fixed nesting issue with verbose property notation #297

## 2.0.6

- Added Deserializer for converting json string into a Swagger Annotations object. #290
- Various readme improvements #284 #286
- Various PSR-2 coding standard fixes #291
- Travis now enforces passing PHP CodeSniffer PSR-2 tests #291
- Use badges from shields.io #288

## 2.0.5

- Removed JSON-Schema properties that are not supported in swagger. #273
- Added ordering filenames to guarantee a consistent output #263

## 2.0.4

- Fixed minor regression #254
- Removed format restrictions from the remaining annotations #253

## 2.0.3

- Removed format restrictions #253
- Fixed a bug with inherited properties #250

## 2.0.2

- Added support for @SWG\Head & @SWG\Options for documenting the HEAD and OPTIONS responses
- Removed restrictions in @SWG\Items, allow @SWG\Property and other @SWG\Schema options.

## 2.0.1

- Minimal support for traits (no inheritance)

## 2.0.0

- Generates swagger.json with Swagger Specification v2
- New simplified architecture (crawl -> analysis -> processors -> validation -> output)
The changelog is moved to the [releases page](https://github.com/zircote/swagger-php/releases)
6 changes: 3 additions & 3 deletions Examples/misc/misc-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

/**
* @OAS\Server(
* @OAS\Server(
* url="{schema}://host.dev",
* description="OpenApi parameters",
* @OAS\ServerVariable(
* serverVariable="schema",
* enum="['https', 'http']",
* default="https"
* )
* )
*/
* )
*/
9 changes: 3 additions & 6 deletions Examples/openapi-spec/RepositoriesControler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

class RepositoriesController
{

/**
* @OAS\Get(path="/2.0/repositories/{username}",
* operationId="getRepositoriesByOwner",
* @OAS\Parameter(name="username",
* @OAS\Parameter(
* name="username",
* in="path",
* required=true,
* @OAS\Schema(type="string")
Expand All @@ -21,7 +21,6 @@ class RepositoriesController
* @OAS\Link(link="userRepository", ref="#/components/links/UserRepository")
* )
* )
*
* @OAS\Link(link="UserRepositories",
* operationId="getRepositoriesByOwner",
* parameters={"username"="$response.body#/username"}
Expand Down Expand Up @@ -51,7 +50,6 @@ public function getRepositoriesByOwner($username)
* )
* )
* )
*
* @OAS\Link(link="UserRepository",
* operationId="getRepository",
* parameters={
Expand Down Expand Up @@ -90,7 +88,6 @@ public function getRepository()
* )
* )
* )
*
* @OAS\Link(link="RepositoryPullRequests",
* operationId="getPullRequestsByRepository",
* parameters={
Expand Down Expand Up @@ -154,7 +151,6 @@ public function getPullRequestsById()
* description="the PR was successfully merged"
* )
* )
*
* @OAS\Link(link="PullRequestMerge",
* operationId="mergePullRequest",
* parameters={
Expand All @@ -168,6 +164,7 @@ public function mergePullRequest()
{
}
}

?>


Expand Down
5 changes: 4 additions & 1 deletion Examples/using-refs/api-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
* request="product_in_body",
* required=true,
* description="product_request",
* ref="#/components/schemas/Product"
* @OAS\MediaType(
* mediaType="application/json",
* @OAS\Schema(ref="#/components/schemas/Product")
* )
* )
*/
?>
Expand Down
2 changes: 1 addition & 1 deletion src/Annotations/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Components extends AbstractAnnotation
/**
* Reusable Request Bodys.
*
* @var Request[]
* @var RequestBody[]
*/
public $requestBodies;

Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Header.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Annotations/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OpenApi extends AbstractAnnotation
* Only one of the security requirement objects need to be satisfied to authorize a request.
* Individual operations can override this definition.
*
* @var \Swagger\Annotations\SecurityScheme
* @var SecurityScheme
*/
public $security;

Expand Down
7 changes: 3 additions & 4 deletions src/Annotations/RequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ class RequestBody extends AbstractAnnotation
public $required;

/**
* A map containing descriptions of potential response payloads.
* The key is a media type or media type range and the value describes it.
* For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides
* text/*
* The content of the request body.
* The key is a media type or media type range and the value describes it. For requests that match multiple keys,
* only the most specific key is applicable. e.g. text/plain overrides text/*
*
* @var MediaType[]
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Annotations/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class Schema extends AbstractAnnotation

/**
* An instance validates successfully against this property if it validates successfully against exactly one schema defined by this property's value.
* @var type
* @var Schema[]
*/
public $oneOf;

Expand Down
31 changes: 31 additions & 0 deletions tests/Fixtures/UsingVar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: sonrac
* Date: 3/12/18
* Time: 10:25 AM
*/

namespace SwaggerTests\Fixtures;

/**
* @OAS\Schema(
* schema="UsingVar",
* type="object",
* required={"name"}
* )
*/
class UsingVar
{
/**
* @var string
* @OAS\Property
*/
private $name;

/**
* @var \DateTimeInterface
* @OAS\Property(ref="#/components/schemas/date")
*/
private $createdAt;
}
21 changes: 15 additions & 6 deletions tests/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace SwaggerTests;

use Swagger\StaticAnalyser;

class ItemsTest extends SwaggerTestCase
{
public function testTypeArray()
Expand All @@ -15,10 +17,17 @@ public function testTypeArray()
$annotations[0]->validate();
}

// public function testTypeObject()
// {
// $notAllowedInQuery = $this->parseComment('@OAS\Parameter(name="param",in="query",type="array",@OAS\Items(type="object"))');
// $this->assertSwaggerLogEntryStartsWith('@OAS\Items()->type="object" not allowed inside a @OAS\Parameter() must be "string", "number", "integer", "boolean", "array" in ');
// $notAllowedInQuery[0]->validate();
// }
public function testRefDefinitionInProperty()
{
$analyser = new StaticAnalyser();
$analysis = $analyser->fromFile(__DIR__ . '/Fixtures/UsingVar.php');
$analysis->process();
$this->assertCount(1, $analysis->openapi->components->schemas);
$this->assertEquals('UsingVar', $analysis->openapi->components->schemas[0]->schema);
$this->assertInternalType('array', $analysis->openapi->components->schemas[0]->properties);
$this->assertCount(2, $analysis->openapi->components->schemas[0]->properties);
$this->assertEquals('name', $analysis->openapi->components->schemas[0]->properties[0]->property);
$this->assertEquals('createdAt', $analysis->openapi->components->schemas[0]->properties[1]->property);
$this->assertEquals('#/components/schemas/date', $analysis->openapi->components->schemas[0]->properties[1]->ref);
}
}

0 comments on commit d5a2db7

Please sign in to comment.