Skip to content

Commit

Permalink
Add file upload support to Python example requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed May 14, 2020
1 parent 40461b1 commit 6b32e28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 19 additions & 1 deletion resources/views/partials/example-requests/python.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import json

url = '{{ rtrim($baseUrl, '/') }}/{{ ltrim($route['boundUri'], '/') }}'
@if(count($route['fileParameters']))
files = {
@foreach($route['fileParameters'] as $name => $file)
'{!! $name !!}': open('{!! $file->path() !!}', 'rb')@if(!($loop->last)),
@endif
@endforeach

}
@endif
@if(count($route['cleanBodyParameters']))
payload = {!! json_encode($route['cleanBodyParameters'], JSON_PRETTY_PRINT) !!}
@endif
Expand All @@ -17,7 +26,16 @@
@endforeach

}

@endif
response = requests.request('{{$route['methods'][0]}}', url{{ count($route['headers']) ?', headers=headers' : '' }}{{ count($route['cleanBodyParameters']) ? ', json=payload' : '' }}{{ count($route['cleanQueryParameters']) ? ', params=params' : ''}})
@php
$optionalArguments = [];
if (count($route['headers'])) $optionalArguments[] = "headers=headers";
if (count($route['fileParameters'])) $optionalArguments[] = "files=files";
if (count($route['cleanBodyParameters'])) $optionalArguments[] = (count($route['fileParameters']) ? "data=payload" : "json=payload");
if (count($route['cleanQueryParameters'])) $optionalArguments[] = "params=params";
$optionalArguments = implode(', ',$optionalArguments);
@endphp
response = requests.request('{{$route['methods'][0]}}', url, {{ $optionalArguments }})
response.json()
```
9 changes: 0 additions & 9 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Documentation tasks
- Rewritten docs. Some things to document:
- plugin api: responses - description, $stage property, scribe:strategy
- fileParams

# Release blocker
- Port recent changes from old repo

# Features
- Possible feature: https://github.com/mpociot/laravel-apidoc-generator/issues/731
- file input python

0 comments on commit 6b32e28

Please sign in to comment.