Skip to content

Commit

Permalink
Implemented @swg\Info & @swg\Authorizations which can be used to augm…
Browse files Browse the repository at this point in the history
…ent the api-docs.json with metadata.

Also updated wordnik/swagger-core/wiki/ urls to the wordnik/swagger-spec/
  • Loading branch information
bfanger committed Aug 12, 2014
1 parent c652fe3 commit 1fdc544
Show file tree
Hide file tree
Showing 21 changed files with 559 additions and 122 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@
Changelog
----------

## 0.9.5

* Implemented @SWG\Info & @SWG\Authorizations which can be used to augment the api-docs.json with metadata.
* Updated @link references to the github.com/wordnik/swagger-spec repository

## 0.9.4

* Fixed regressions #145 & #146
Expand All @@ -28,7 +33,7 @@ Changelog

* New processing architecture allowing swagger-php to act on other annotations (https://github.com/zircote/swagger-php/pull/121)
* Improved model referencing: $ref allowed with complex modelnames (https://github.com/zircote/swagger-php/pull/122 and https://github.com/zircote/swagger-php/pull/123)
* Updated depedencies creating a 50% smaller swagger.phar
* Updated dependencies creating a 50% smaller swagger.phar

## 0.8.3

Expand All @@ -46,7 +51,7 @@ Detect @SWG\Parameter type and @SWG\Items based on `@var Type[]` phpdoc comments
## 0.8.0

* Compatible with swagger-ui 2.0
* Upgraded annotations to the [Swagger 1.2 Specification](https://github.com/wordnik/swagger-core/wiki/1.2-transition)
* Upgraded annotations to the [Swagger 1.2 Specification](https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md)
* Use swagger-php 0.7.x to generate 1.1 or older swagger specs.
* Simplified API.
* Removed many methods from the Swagger class.
Expand Down Expand Up @@ -105,4 +110,4 @@ Detect @SWG\Parameter type and @SWG\Items based on `@var Type[]` phpdoc comments
* An @Api can be nested inside a @Resource and @Property can be nested inside a @Model.

## Olders versions
Checkout the [commit log](https://github.com/zircote/swagger-php/commits) for the changes from 0.1 to 0.4
Checkout the [commit log](https://github.com/zircote/swagger-php/commits) for the changes from 0.1 to 0.4
4 changes: 2 additions & 2 deletions Examples/Facet/Resources/FacetResource.php
Expand Up @@ -14,7 +14,8 @@
* apiVersion="0.2",
* swaggerVersion="1.2",
* resourcePath="/facet",
* basePath="http://facetstore.zircote.com/swagger-php/api"
* basePath="http://facetstore.zircote.com/swagger-php/api",
* produces="['application/json']"
* )
*/
class FacetResource
Expand All @@ -24,7 +25,6 @@ class FacetResource
* @SWG\Api(
* path="/facet.{format}/{facetId}",
* description="Operations about facets",
* produces="['application/json']",
* @SWG\Operations(
* @SWG\Operation(
* method="GET",
Expand Down
25 changes: 0 additions & 25 deletions library/Swagger/Annotations/Api.php
Expand Up @@ -48,31 +48,8 @@ class Api extends AbstractAnnotation
*/
public $operations = array();

/**
* @var array
*/
public $produces;

/**
* @var array
*/
public $consumes;

/**
* Undocumented
* @var bool
*/
public $deprecated;

/**
* @var Undocumented
*/
public $defaultValue;

protected static $mapAnnotations = array(
'\Swagger\Annotations\Operation' => 'operations[]',
'\Swagger\Annotations\Produces' => 'produces[]',
'\Swagger\Annotations\Consumes' => 'consumes[]',
);

public function __construct(array $values = array())
Expand Down Expand Up @@ -106,8 +83,6 @@ public function validate()
Logger::notice('Api "'.$this->path.'" doesn\'t have any valid operations');
return false;
}
Produces::validateContainer($this);
Consumes::validateContainer($this);
return true;
}

Expand Down
85 changes: 85 additions & 0 deletions library/Swagger/Annotations/Authorization.php
@@ -0,0 +1,85 @@
<?php

namespace Swagger\Annotations;

/**
* @license http://www.apache.org/licenses/LICENSE-2.0
* Copyright [2013] [Robert Allen]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package
* @category
* @subpackage
*/
use Swagger\Logger;

/**
* Provide information about the authorization schemes provided on this API.
* @link https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#514-authorizations-object
*
* @package
* @category
* @subpackage
*
* @Annotation
*/
class Authorization extends AbstractAnnotation
{

/**
* The type of the authorization scheme.
* @var string
*/
public $type;

/**
* Denotes how the API key must be passed. Valid values are "header" or "query".
* @var string
*/
public $passAs;

/**
* The name of the header or query parameter to be used when passing the API key.
* @var string
*/
public $keyname;

/**
* A list of supported OAuth2 scopes.
* @var Scope[]
*/
public $scopes;

/**
* Detailed information about the grant types supported by the OAuth2 authorization scheme.
* @var object
*/
public $grantTypes;

protected static $mapAnnotations = array(
'\Swagger\Annotations\Scope' => 'scopes[]'
);

public function validate() {
if (in_array($this->type, array('basicAuth', 'apiKey', 'oauth2')) === false) {
Logger::warning('Unexpected '.$this->identity().'->type "'.$this->type.'", expection "basicAuth", "apiKey" or "oauth2" in '.$this->_context);
return false;
}
if ($this->type === 'apiKey' && (empty($this->passAs) || empty($this->keyname))) {
Logger::notice('Fields "passAs" and "keyname" are required for '.$this->identity().'->type "apiKey" in '.$this->_context);
}
return true;
}

}
14 changes: 9 additions & 5 deletions library/Swagger/Annotations/DataType.php
Expand Up @@ -28,13 +28,14 @@

/**
* Baseclass for the @SWG\Parameter & @SWG\Property annotations.
* @link https://github.com/wordnik/swagger-core/wiki/datatypes
* https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#43-data-types
*
* @package
* @category
* @subpackage
*
* @Annotation
* @link https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#43-data-types
*/
abstract class DataType extends AbstractAnnotation
{
Expand All @@ -55,17 +56,19 @@ abstract class DataType extends AbstractAnnotation
public $type;

/**
*
* Fine-tuned primitive type definition
* @var string
*/
public $format;

/**
* The type definition of the values in the container.
* @var Items
*/
public $items;

/**
* A flag to note whether the container allows duplicate values or not.
* @var bool
*/
public $uniqueItems;
Expand All @@ -76,24 +79,25 @@ abstract class DataType extends AbstractAnnotation
public $required;

/**
*
* The minimum valid value for the type, inclusive.
* @var mixed
*/
public $minimum;

/**
*
* The maximum valid value for the type, inclusive.
* @var mixed
*/
public $maximum;

/**
* A fixed list of possible values.
* @var array
*/
public $enum;

/**
* Undocumented
* The default value to be used for the field.
* @var mixed
*/
public $defaultValue;
Expand Down
86 changes: 86 additions & 0 deletions library/Swagger/Annotations/Info.php
@@ -0,0 +1,86 @@
<?php

namespace Swagger\Annotations;

/**
* @license http://www.apache.org/licenses/LICENSE-2.0
* Copyright [2013] [Robert Allen]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package
* @category
* @subpackage
*/
use Swagger\Logger;

/**
* Describes the metadata about the API.
* @link https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#513-info-object
*
* @package
* @category
* @subpackage
*
* @Annotation
*/
class Info extends AbstractAnnotation
{

/**
* The title of the application.
* @var string
*/
public $title;

/**
* A short description of the application.
* @var string
*/
public $description;

/**
* A URL to the Terms of Service of the API.
* @var string
*/
public $termsOfServiceUrl;

/**
* An email to be used for API-related correspondence.
* @var string
*/
public $contact;

/**
* The license name used for the API.
* @var string
*/
public $license;

/**
* A URL to the license used for the API.
* @var string
*/
public $licenseUrl;

public function validate()
{
foreach (array('title', 'description') as $required) {
if (empty($this->$required)) {
Logger::notice('Required field "'.$required.'" is missing for "'.$this->identity().'" in '.$this->_context);
return false;
}
}
return true;
}
}
13 changes: 9 additions & 4 deletions library/Swagger/Annotations/Model.php
Expand Up @@ -30,29 +30,34 @@
* @subpackage
*
* @Annotation
* @link https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#527-model-object
*/
class Model extends AbstractAnnotation
{
/**
* A unique identifier for the model.
* @var string
*/
public $id;

/**
* A brief description of this model.
* @var string
*/
public $description;

/**
* A definition of which properties must exist when a model instance is produced.
* @var array
*/
public $properties = array();
public $required;

/**
* @var array
* A list of properties (fields) that are part of the model.
* @var Property[]
*/
public $required;

public $properties = array();
protected static $mapAnnotations = array(
'\Swagger\Annotations\Property' => 'properties[]'
);
Expand Down

0 comments on commit 1fdc544

Please sign in to comment.