Skip to content

Commit

Permalink
Merge pull request #12 from ianmustafa/docs-update-for-api-app
Browse files Browse the repository at this point in the history
Improve documentation for API-only projects
  • Loading branch information
ahmadarif committed Jan 7, 2019
2 parents a28df38 + ef2a80e commit b735371
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ adonis install adonis-swagger
]
```

* Other configuration please update the `config/swagger.js` file.
* **Note:** For projects that uses API-only blueprint (using `--api-only` flag), please
enable `Adonis/Middleware/Static` under `serverMiddleware` in `start/kernel.js`:
```js
const serverMiddleware = [
'Adonis/Middleware/Static',
...
]
```

* For other configuration, please update the `config/swagger.js`.

# Sample Usage
* Add new route
* Add new route:
```js
Route.get('/api/hello', 'TestController.hello')
```

* Create TestController using command adonis make:controller Test
* Create `TestController` using `adonis make:controller Test` command:
```js
'use strict'

Expand Down Expand Up @@ -63,7 +72,7 @@ adonis install adonis-swagger
module.exports = TestController
```

* You can also define the schema in the Models
* You can also define the schema in the Models:
```js
'use strict'

Expand Down Expand Up @@ -108,18 +117,17 @@ adonis install adonis-swagger
│ ├── **/*.yml
```

* Other sample in YAML and JS format please refer this [link](/sample)

* For other sample in YAML and JS format, please refer to this [link](/sample).

Open http://localhost:3333/docs in your browser, ayeey 🎉 </br>
For detail usage, please check the swagger specification in this [link][SwaggerSpec].
Open http://localhost:3333/docs in your browser, ayeey 🎉
For detail usage, please check the Swagger specification in this [link][SwaggerSpec].

# Command List
Command | Description
:-----------------------------|:-----------
`adonis swagger:export` | Export config file & swagger-ui assets
`adonis swagger:remove` | Remove config file & swagger-ui assets
`adonis swagger:remove-docs` | Remove swagger-ui only
`adonis swagger:export` | Export config file & `swagger-ui` assets. <br>**Warning: This will reset your `config/swagger.js`!**<br>Please use with caution.
`adonis swagger:remove` | Remove config file & `swagger-ui` assets
`adonis swagger:remove-docs` | Remove `swagger-ui` only

# Dependencies
- [swagger-jsdocs](https://www.npmjs.com/package/swagger-jsdoc)
Expand All @@ -130,4 +138,4 @@ Special thanks to the creator(s) of [AdonisJS][AdonisJS] for creating such a gre

[Swagger]:https://swagger.io/
[SwaggerSpec]:https://swagger.io/specification/
[AdonisJS]: http://adonisjs.com/
[AdonisJS]: http://adonisjs.com/
34 changes: 23 additions & 11 deletions instructions.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Registering provider
```js
const providers = [
...
'adonis-swagger/providers/SwaggerProvider'
]
```
# Configuration
* Register `SwaggerProvider` in `start/app.js`:
```js
const providers = [
...
'adonis-swagger/providers/SwaggerProvider'
]
```

* **Note:** For projects that uses API-only blueprint (using `--api-only` flag), please
enable `Adonis/Middleware/Static` under `serverMiddleware` in `start/kernel.js`:
```js
const serverMiddleware = [
'Adonis/Middleware/Static',
...
]
```

* For other configuration, please update the `config/swagger.js`.

# Usage
* Add new route
* Add new route:
```js
Route.get('/api/hello', 'TestController.hello')
```

* Create TestController using command adonis make:controller Test
* Create `TestController` using `adonis make:controller Test` command:
```js
'use strict'

Expand Down Expand Up @@ -46,7 +58,7 @@ const providers = [
module.exports = TestController
```

* You can also define the schema in the Models
* You can also define the schema in the Models:
```js
'use strict'

Expand Down Expand Up @@ -93,4 +105,4 @@ const providers = [

> For custom directory, please change the `config/swagger.js` as needed.
* Other sample in YAML and JS format please refer this [link](https://github.com/ahmadarif/adonis-swagger/tree/master/sample)
* For other sample in YAML and JS format, please refer to this [link](https://github.com/ahmadarif/adonis-swagger/tree/master/sample)

0 comments on commit b735371

Please sign in to comment.