Skip to content

Commit d07f68a

Browse files
authored
Merge pull request #524 from IcaroJerry/master
Include Python as example language
2 parents 2f3a214 + 6f28592 commit d07f68a

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

config/apidoc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198

199199
/*
200200
* Example requests for each endpoint will be shown in each of these languages.
201-
* Supported options are: bash, javascript, php
201+
* Supported options are: bash, javascript, php, python
202202
* You can add a language of your own, but you must publish the package's views
203203
* and define a corresponding view for it in the partials/example-requests directory.
204204
* See https://laravel-apidoc-generator.readthedocs.io/en/latest/generating-documentation.html

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ If you want to use this, please note that the image size must be 230 x 52.
3535
When [documenting your api](documenting.md), you use `@group` annotations to group API endpoints. Endpoints which do not have a ggroup annotation will be grouped under the `default_group`. Defaults to **"general"**.
3636

3737
## `example_languages`
38-
For each endpoint, an example request is shown in each of the languages specified in this array. Currently only `bash`, `javascript` and `php` are supported. You can add your own language, but you must also define the corresponding view (see [Specifying languages for examples](generating-documentation.html#specifying-language-for-examples)). Default: `["bash", "javascript"]`
38+
For each endpoint, an example request is shown in each of the languages specified in this array. Currently only `bash`, `javascript`, `php` and `python` are supported. You can add your own language, but you must also define the corresponding view (see [Specifying languages for examples](generating-documentation.html#specifying-language-for-examples)). Default: `["bash", "javascript"]`
3939

4040
## `faker_seed`
4141
When generating example requests, this package uses fzanninoto/faker to generate random values. If you would like the package to generate the same example values for parameters on each run, set this to any number (eg. 1234). (Note: alternatively, you can set example values for parameters when [documenting them.](documenting.html#specifying-request-parameters))

docs/generating-documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ php artisan apidoc:rebuild
4747

4848
This will copy the views files to `\resources\views\vendor\apidoc`.
4949

50-
- Next, create a file called {language-name}.blade.php (for example, python.blade.php) in the partials/example-requests directory. You can then write Markdown with Blade templating that describes how the example request for the language should be rendered. You have the `$route` variable available to you. This variable is an array with the following keys:
50+
- Next, create a file called {language-name}.blade.php (for example, ruby.blade.php) in the partials/example-requests directory. You can then write Markdown with Blade templating that describes how the example request for the language should be rendered. You have the `$route` variable available to you. This variable is an array with the following keys:
5151
- `methods`: an array of the HTTP methods for that route
5252
- `boundUri`: the complete URL for the route, with any url parameters replaced (/users/{id} -> /users/1)
5353
- `headers`: key-value array of headers to be sent with route (according to your configuration)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```python
2+
import requests
3+
import json
4+
5+
url = '{{ rtrim($baseUrl, '/') }}/{{ ltrim($route['boundUri'], '/') }}'
6+
@if(count($route['cleanBodyParameters']))
7+
payload = {
8+
@foreach($route['cleanBodyParameters'] as $attribute => $parameter)
9+
'{{ $attribute }}': '{{ $parameter['value'] }}'@if(!($loop->last)),@endif {{ !$parameter['required'] ? '# optional' : '' }}
10+
@endforeach
11+
}
12+
@endif
13+
@if(count($route['cleanQueryParameters']))
14+
params = {
15+
@foreach($route['cleanQueryParameters'] as $attribute => $parameter)
16+
'{{ $attribute }}': '{{ $parameter['value'] }}'@if(!($loop->last)),@endif {{ !$parameter['required'] ? '# optional' : '' }}
17+
@endforeach
18+
}
19+
@endif
20+
headers = {
21+
@foreach($route['headers'] as $header => $value)
22+
'{{$header}}': '{{$value}}'@if(!($loop->last)),@endif
23+
@endforeach
24+
}
25+
response = requests.request('{{$route['methods'][0]}}', url, headers=headers{{ count($route['cleanBodyParameters']) ? ', json=payload' : '' }}{{ count($route['cleanQueryParameters']) ? ', params=params' : ''}})
26+
response.json()
27+
```

0 commit comments

Comments
 (0)