Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
<?php | ||
namespace gossi\swagger; | ||
|
||
class SecurityScheme { | ||
use phootwork\lang\Arrayable; | ||
|
||
class SecurityScheme extends AbstractModel implements Arrayable { | ||
|
||
/** @var string */ | ||
private $name; | ||
|
||
/** @var string */ | ||
private $type; | ||
|
||
/** @var string */ | ||
private $description; | ||
|
||
/** | ||
* @param string $name | ||
* @param array $contents | ||
*/ | ||
public function __construct($name, $contents = []) { | ||
$this->name = $name; | ||
$this->parse($contents); | ||
} | ||
|
||
/** | ||
* @param array $contents | ||
*/ | ||
private function parse($contents = []) { | ||
$this->type = $contents->get('type'); | ||
$this->description = $contents->get('description'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() { | ||
return $this->export('type', 'description'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
namespace gossi\swagger\parts; | ||
|
||
use phootwork\collection\Map; | ||
|
||
trait SecurityPart { | ||
|
||
/** @var object */ | ||
private $security; | ||
|
||
private function parseSecurity(Map $data) { | ||
$this->security = $data->get('security'); | ||
} | ||
|
||
/** | ||
* @return object | ||
*/ | ||
public function getSecurity() { | ||
return $this->security; | ||
} | ||
|
||
/** | ||
* @param object $security | ||
* @return $this | ||
*/ | ||
public function setSecurity($security) { | ||
$this->security = $security; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace gossi\swagger\tests; | ||
|
||
use gossi\swagger\Swagger; | ||
use phootwork\file\exception\FileNotFoundException; | ||
use phootwork\file\File; | ||
use phootwork\json\Json; | ||
|
||
class BasicAuth extends \PHPUnit_Framework_TestCase { | ||
|
||
private function fileToArray($filename) { | ||
$file = new File($filename); | ||
|
||
if (!$file->exists()) { | ||
throw new FileNotFoundException(sprintf('File not found at: %s', $filename)); | ||
} | ||
|
||
return Json::decode($file->read()); | ||
} | ||
|
||
public function testUser() { | ||
$filename = __DIR__ . '/fixtures/basic-auth.json'; | ||
$swagger = Swagger::fromFile($filename); | ||
|
||
$this->assertEquals($this->fileToArray($filename), $swagger->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"version": "1.0.0", | ||
"title": "Basic Auth Example", | ||
"description": "An example for how to use Basic Auth with Swagger.\nServer code is available [here](https://github.com/mohsen1/basic-auth-server). It's running on Heroku.\n\n**User Name and Password**\n* User Name: `user`\n* Password: `pass`\n" | ||
}, | ||
"host": "basic-auth-server.herokuapp.com", | ||
"schemes": [ | ||
"http", | ||
"https" | ||
], | ||
"securityDefinitions": { | ||
"basicAuth": { | ||
"type": "basic", | ||
"description": "HTTP Basic Authentication. Works over `HTTP` and `HTTPS`" | ||
} | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"security": [ | ||
{ | ||
"basicAuth": [] | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "Will send `Authenticated` if authentication is succesful, otherwise it will send `Unauthorized`" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |