Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Changed errors to responseCodes; Updated README;
Browse files Browse the repository at this point in the history
  • Loading branch information
szytko committed Dec 18, 2014
1 parent 270b37a commit f333905
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 49 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Usage
#### Add vegas-cmf/apidoc to composer.json dependencies

```
"vegas-cmf/apidoc" : "1.0.0"
"vegas-cmf/apidoc" : "1.0.*"
```

and run composer update
Expand Down Expand Up @@ -93,10 +93,6 @@ class TestController extends ControllerAbstract
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 404', description: 'Test was not found'},
* {type: 'Error 500', description: 'Application error'}
* ],
* requestFormat='JSON',
* requestContentType='application/json',
* request={
Expand All @@ -111,6 +107,13 @@ class TestController extends ControllerAbstract
* {name: 'id', type: 'MongoId', description: 'Test ID'},
* {name: 'name', type: 'string', description: 'Foo name'}
* ],
* responseCodes=[
* {code: 111, type: 'Info', description: 'Connection refused'},
* {code: 200, type: 'Success', description: 'OK'},
* {code: 300, type: 'Redirect', description: 'Found'},
* {code: 404, type: 'Error', description: 'Record not found'},
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* responseExample='{
* "id": "123",
* "name": "Test"
Expand Down Expand Up @@ -149,8 +152,9 @@ class TestController extends ControllerAbstract
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 500', description: 'Unknown error'}
* responseCodes=[
* {code: 500, type: 'Error', description: 'Unknown error'}
* {code: 200, type: 'Success', description: 'Ok'}
* ],
* requestFormat='JSON',
* requestContentType='application/json',
Expand Down Expand Up @@ -228,8 +232,6 @@ class TestController extends ControllerAbstract

`headers` Describes headers passed in request e.g. for Authorization

`errors` Describes errors

`request` Describes request

`requestContentType` Determines request Content-Type
Expand All @@ -246,6 +248,7 @@ class TestController extends ControllerAbstract

`responseExample` Example of response body

`responseCodes` Describes response status codes

#### Create documentation layout ( you can use sample layout from tests/fixtures/app/layouts/partials/apiDoc directory ) and prepare output directory

Expand All @@ -263,4 +266,4 @@ mkdir public/apiDoc
php cli/cli.php app:apidoc generate
```

Check example documentation [http://jsbin.com/sigebogegu/1](http://jsbin.com/sigebogegu/1)
See sample [http://jsbin.com/xeyetevuro/1](http://jsbin.com/xeyetevuro/1)
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "vegas-cmf/apidoc",
"version" : "",
"type": "library",
"description": "Vegas CMF API Documentor",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions src/Collection/MethodCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 404', description: 'Object was not found'},
* {type: 'Error 500', description: 'Application error'}
* responseCodes=[
* {code: 400, type: 'Error', description: 'Object was not found'},
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* requestFormat='JSON',
* requestContentType='application/json',
Expand Down Expand Up @@ -67,8 +67,6 @@ class MethodCollection extends CollectionAbstract

public $headers;

public $errors;

public $request;

public $requestContentType;
Expand All @@ -85,6 +83,8 @@ class MethodCollection extends CollectionAbstract

public $responseExample;

public $responseCodes;

public $description;

public $name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{ partial('apiDoc/partials/method/method', ['method': method]) }}
{{ partial('apiDoc/partials/method/url', ['method': method]) }}
{{ partial('apiDoc/partials/method/params', ['method': method]) }}
{{ partial('apiDoc/partials/method/errors', ['method': method]) }}
{{ partial('apiDoc/partials/method/responseCodes', ['method': method]) }}

<div class="clearfix"></div>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% if method['requestContentType'] is defined and method['requestContentType']|length > 0 %}
<pre>Content-Type: <span class="label label-primary"><h5 style="display:inline;">{{ method['requestContentType'] }}</h5></span></pre>
<pre>Content-Type: <span class="label label-primary">{{ method['requestContentType'] }}</span></pre>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% if method['responseCodes'] is defined and method['responseCodes'] is type('array') and method['responseCodes']|length > 0 %}
<h4>Errors</h4>
<table class="table table-bordered table-hover">
<tr>
<th>Code</th>
<th>Type</th>
<th>Description</th>
</tr>
{% for responseCode in method['responseCodes'] %}
<tr>
{% if responseCode['code'] < 200 %}
<td><span class="label label-info">{{ responseCode['code'] }}</span></td>
{% endif %}
{% if responseCode['code'] >= 200 and responseCode['code'] < 300 %}
<td><span class="label label-success">{{ responseCode['code'] }}</span></td>
{% endif %}
{% if responseCode['code'] >= 300 and responseCode['code'] < 400 %}
<td><span class="label label-default">{{ responseCode['code'] }}</span></td>
{% endif %}
{% if responseCode['code'] >= 400 and responseCode['code'] < 500 %}
<td><span class="label label-warning">{{ responseCode['code'] }}</span></td>
{% endif %}
{% if responseCode['code'] >= 500 and responseCode['code'] %}
<td><span class="label label-danger">{{ responseCode['code'] }}</span></td>
{% endif %}
<td>{{ responseCode['type'] }}</td>
<td>{{ responseCode['description'] }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
10 changes: 5 additions & 5 deletions tests/fixtures/app/modules/ApiTest/controllers/FooController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class FooController extends ControllerAbstract
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 404', description: 'Foo was not found'},
* {type: 'Error 500', description: 'Application error'}
* responseCodes=[
* {code: 404, type: 'Error', description: 'Record not found'},
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* responseFormat='JSON',
* responseContentType='application/json',
Expand Down Expand Up @@ -78,8 +78,8 @@ public function getAction()
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 500', description: 'Unknown error'}
* responseCodes=[
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* responseFormat='JSON',
* responseContentType='application/json',
Expand Down
17 changes: 10 additions & 7 deletions tests/fixtures/app/modules/ApiTest/controllers/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class TestController extends ControllerAbstract
* headers={
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* },
* errors={
* {type: 'Error 404', description: 'Test was not found'},
* {type: 'Error 500', description: 'Application error'}
* },
* responseCodes=[
* {code: 111, type: 'Info', description: 'Connection refused'},
* {code: 200, type: 'Success', description: 'OK'},
* {code: 300, type: 'Redirect', description: 'Found'},
* {code: 404, type: 'Error', description: 'Record not found'},
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* requestFormat='JSON',
* requestContentType='application/json',
* request={
Expand Down Expand Up @@ -89,9 +92,9 @@ public function getAction()
* headers={
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* },
* errors={
* {type: 'Error 500', description: 'Unknown error'}
* },
* responseCodes=[
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* requestFormat='JSON',
* requestContentType='application/json',
* request='',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class NestedController extends ControllerAbstract
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 404', description: 'Nested was not found'},
* {type: 'Error 500', description: 'Application error'}
* responseCodes=[
* {code: 404, type: 'Error', description: 'Record not found'},
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* responseFormat='JSON',
* responseContentType='application/json',
Expand Down Expand Up @@ -78,8 +78,8 @@ public function getAction()
* headers=[
* {name: 'HTTP_X_AUTH', description: 'Authentication token'}
* ],
* errors=[
* {type: 'Error 500', description: 'Unknown error'}
* responseCodes=[
* {code: 500, type: 'Error', description: 'Application error'}
* ],
* responseFormat='JSON',
* responseContentType='application/json',
Expand Down

0 comments on commit f333905

Please sign in to comment.