Skip to content

Commit

Permalink
README, ublaboo -> contributte
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed May 3, 2020
1 parent ed06026 commit 5096bc4
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 210 deletions.
162 changes: 162 additions & 0 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# ApiDocu

ApiDocu can generate api documentation for routes created using [ApiRouter](https://github.com/contributte/api-router). It works either for directly defined routes or the ones defined via annotation.</p>

## Installing ApiDocu

ApiDocu is available through composer package `contributte/api-docu`:

```
composer require contributte/api-docu
```

## Usage - runtime documentation

![Route docs](assets/route-docs.png)

### GET routes

ApiDocu can show you api documentation for current route, if there is any. Just visit the api url and add a `?__apiDocu` parameter in you address bar.

### PUT, POST, DELETE routes

But you cat match only routes with GET method when you are comming through browser window. Route method can by changed using `?__apiRouteMethod` query parameter. To visit PUT route api documentation you have to write something like that: `/users/10?__apiRouteMethod=DELETE&__apiDocu`. Here is an example: `/api-router/api/users/8?__apiRouteMethod=PUT&__apiDocu`.

### Presenter code:

```php
<?php

namespace App\ResourcesModule\Presenters;

use Nette;
use Contributte\ApiRouter\ApiRoute;

/**
* API for managing users
*
* @ApiRoute(
* "/api-router/api/users[/<id>]",
* parameters={
* "id"={
* "requirement": "\d+",
* "type": "integer",
* "description": "User ID",
* "default": 10
* }
* },
* priority=1,
* format="json",
* section="Users",
* presenter="Resources:Users"
* )
*/
class UsersPresenter extends Nette\Application\UI\Presenter
{

/**
* Get user detail
*
* You **can** also write example json in the description
*
* <json>
* {
* "name": "John",
* "surname": "Doe",
* "age": 23,
* "hairCount": 123456,
* "parents": {{
* "name": "John",
* "surname": "Doe",
* "age": 53,
* "hairCount": 456
* }}
* }
* </json>
*
* @ApiRoute(
* "/api-router/api/users/<id>[/<foo>-<bar>]",
* parameters={
* "id"={
* "requirement": "\d+",
* "type": "integer",
* "description": "User ID",
* "default": 10
* }
* },
* method="GET",
* format="json",
* example={
* "name": "John",
* "surname": "Doe",
* "age": 23,
* "hairCount": 123456,
* "parents": {{
* "name": "John",
* "surname": "Doe",
* "age": 53,
* "hairCount": 456
* }}
* },
* tags={
* "public",
* "secured": "#e74c3c"
* },
* response_codes={
* 200="Success",
* 400="Error in authentication process",
* 401="Invalid authentication"
* }
* )
*/
public function actionRead($id, $foo = NULL, $bar = NULL)
{
$this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]);
}


public function actionUpdate($id)
{
$this->sendJson(['id' => $id]);
}


public function actionDelete($id)
{
$this->sendJson(['id' => $id]);
}

}
```

## Generating API documentation

![Docs](assets/docs.png)

### `?__apiDocuGenerate`

When you are directly on some api url, you can use query parameter `?__apiDocuGenerate` for generating whole application api documentation. All documentation files will be available in directory specified by you. By default, the directory is:

```
apiDocu:
apiDir: "%wwwDir%/api"
extensions:
apiRouter: Contributte\ApiRouter\DI\ApiRouterExtension
apiDocu: Contributte\ApiDocu\DI\ApiDocuExtension
```

Example api generation trigger is here: `/api-router/api/books?__apiDocuGenerate`.

## HTTP authorization

You can use a HTTP authorization on your documentation sites:

```
apiDocu:
apiDir: "%wwwDir%/client-api"
httpAuth:
user: foo
password: bar
```
File renamed without changes
File renamed without changes
216 changes: 48 additions & 168 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,168 +1,48 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ublaboo/api-docu/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ublaboo/api-docu/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/ublaboo/api-docu/v/stable)](https://packagist.org/packages/ublaboo/api-docu)
[![License](https://poser.pugx.org/ublaboo/api-docu/license)](https://packagist.org/packages/ublaboo/api-docu)
[![Total Downloads](https://poser.pugx.org/ublaboo/api-docu/downloads)](https://packagist.org/packages/ublaboo/api-docu)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/ublaboo/help)

# ApiDocu

ApiDocu can generate api documentation for routes created using [ApiRouter](https://github.com/contributte/api-router). It works either for directly defined routes or the ones defined via annotation.</p>

## Installing ApiDocu

ApiDocu is available through composer package `ublaboo/api-docu`:

```
composer require ublaboo/api-docu
```

## Usage - runtime documentation

![Route docs](docs/assets/route-docs.png)

### GET routes

ApiDocu can show you api documentation for current route, if there is any. Just visit the api url and add a `?__apiDocu` parameter in you address bar.

### PUT, POST, DELETE routes

But you cat match only routes with GET method when you are comming through browser window. Route method can by changed using `?__apiRouteMethod` query parameter. To visit PUT route api documentation you have to write something like that: `/users/10?__apiRouteMethod=DELETE&__apiDocu`. Here is an example: `/api-router/api/users/8?__apiRouteMethod=PUT&__apiDocu`.

### Presenter code:

```php
<?php

namespace App\ResourcesModule\Presenters;

use Nette;
use Ublaboo\ApiRouter\ApiRoute;

/**
* API for managing users
*
* @ApiRoute(
* "/api-router/api/users[/<id>]",
* parameters={
* "id"={
* "requirement": "\d+",
* "type": "integer",
* "description": "User ID",
* "default": 10
* }
* },
* priority=1,
* format="json",
* section="Users",
* presenter="Resources:Users"
* )
*/
class UsersPresenter extends Nette\Application\UI\Presenter
{

/**
* Get user detail
*
* You **can** also write example json in the description
*
* <json>
* {
* "name": "John",
* "surname": "Doe",
* "age": 23,
* "hairCount": 123456,
* "parents": {{
* "name": "John",
* "surname": "Doe",
* "age": 53,
* "hairCount": 456
* }}
* }
* </json>
*
* @ApiRoute(
* "/api-router/api/users/<id>[/<foo>-<bar>]",
* parameters={
* "id"={
* "requirement": "\d+",
* "type": "integer",
* "description": "User ID",
* "default": 10
* }
* },
* method="GET",
* format="json",
* example={
* "name": "John",
* "surname": "Doe",
* "age": 23,
* "hairCount": 123456,
* "parents": {{
* "name": "John",
* "surname": "Doe",
* "age": 53,
* "hairCount": 456
* }}
* },
* tags={
* "public",
* "secured": "#e74c3c"
* },
* response_codes={
* 200="Success",
* 400="Error in authentication process",
* 401="Invalid authentication"
* }
* )
*/
public function actionRead($id, $foo = NULL, $bar = NULL)
{
$this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]);
}


public function actionUpdate($id)
{
$this->sendJson(['id' => $id]);
}


public function actionDelete($id)
{
$this->sendJson(['id' => $id]);
}

}
```

## Generating API documentation

![Docs](docs/assets/docs.png)

### `?__apiDocuGenerate`

When you are directly on some api url, you can use query parameter `?__apiDocuGenerate` for generating whole application api documentation. All documentation files will be available in directory specified by you. By default, the directory is:

```
apiDocu:
apiDir: "%wwwDir%/api"
extensions:
apiRouter: Ublaboo\ApiRouter\DI\ApiRouterExtension
apiDocu: Ublaboo\ApiDocu\DI\ApiDocuExtension
```

Example api generation trigger is here: `/api-router/api/books?__apiDocuGenerate`.

## HTTP authorization

You can use a HTTP authorization on your documentation sites:

```
apiDocu:
apiDir: "%wwwDir%/client-api"
httpAuth:
user: foo
password: bar
```
# RabbitMQ

Ultra easy-to-use [`RabbitMQ`](https://www.rabbitmq.com/) implementation for [`Nette Framework`](https://github.com/nette/).

[![Build Status](https://img.shields.io/travis/contributte/api-docu.svg?style=flat-square)](https://travis-ci.org/contributte/api-docu)
[![Code coverage](https://img.shields.io/coveralls/contributte/api-docu.svg?style=flat-square)](https://coveralls.io/r/contributte/api-docu)
[![Licence](https://img.shields.io/packagist/l/contributte/api-docu.svg?style=flat-square)](https://packagist.org/packages/contributte/api-docu)
[![Downloads this Month](https://img.shields.io/packagist/dm/contributte/api-docu.svg?style=flat-square)](https://packagist.org/packages/contributte/api-docu)
[![Downloads total](https://img.shields.io/packagist/dt/contributte/api-docu.svg?style=flat-square)](https://packagist.org/packages/contributte/api-docu)
[![Latest stable](https://img.shields.io/packagist/v/contributte/api-docu.svg?style=flat-square)](https://packagist.org/packages/contributte/api-docu)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat-square)](https://github.com/phpstan/phpstan)

![](https://github.com/contributte/api-docu/blob/master/.docs/assets/route-docs.png "Route docs")

## Discussion / Help

[![Join the chat](https://img.shields.io/gitter/room/contributte/contributte.svg?style=flat-square)](http://bit.ly/ctteg)

## Documentation

- [Installing ApiDocu](.docs/README.md#installing-apidocu)
- [Usage - runtime documentation](.docs/README.md#usage---runtime-documentation)
- [Generating API documentation](.docs/README.md#generating-api-documentation)
- [HTTP authorization](.docs/README.md#http-authorization)

## Versions
z
| State | Version | Branch | Nette | PHP |
|--------|--------------|----------|--------|---------|
| stable | `^3.0.0` | `master` | `3.0+` | `^7.1` |

## Maintainers

<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/paveljanda">
<img width="150" height="150" src="https://avatars0.githubusercontent.com/u/1488874?s=150&v=4">
</a>
</br>
<a href="https://github.com/paveljanda">Pavel Janda</a>
</td>
</tr>
</tbody>
</table>

Thank you for testing, reporting and contributing.
Loading

0 comments on commit 5096bc4

Please sign in to comment.