bash.md.blade.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. @php
  2. use Knuckles\Scribe\Tools\WritingUtils as u;
  3. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  4. @endphp
  5. ```bash
  6. curl --request {{$endpoint->httpMethods[0]}} \
  7. {{$endpoint->httpMethods[0] == 'GET' ? '--get ' : ''}}"{!! rtrim($baseUrl, '/') !!}/{{ ltrim($endpoint->boundUri, '/') }}@if(count($endpoint->cleanQueryParameters))?{!! u::printQueryParamsAsString($endpoint->cleanQueryParameters) !!}@endif"@if(count($endpoint->headers)) \
  8. @foreach($endpoint->headers as $header => $value)
  9. --header "{{$header}}: {{ addslashes($value) }}"@if(! ($loop->last) || ($loop->last && count($endpoint->bodyParameters))) \
  10. @endif
  11. @endforeach
  12. @endif
  13. @if($endpoint->hasFiles() || (isset($endpoint->headers['Content-Type']) && $endpoint->headers['Content-Type'] == 'multipart/form-data' && count($endpoint->cleanBodyParameters)))
  14. @foreach($endpoint->cleanBodyParameters as $parameter => $value)
  15. @foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue)
  16. --form "{!! "$key=".$actualValue !!}"@if(!($loop->parent->last) || count($endpoint->fileParameters))\
  17. @endif
  18. @endforeach
  19. @endforeach
  20. @foreach($endpoint->fileParameters as $parameter => $value)
  21. @foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file)
  22. --form "{!! "$key=@".$file->path() !!}" @if(!($loop->parent->last))\
  23. @endif
  24. @endforeach
  25. @endforeach
  26. @elseif(count($endpoint->cleanBodyParameters))
  27. @if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
  28. --data "{!! http_build_query($endpoint->cleanBodyParameters, '', '&') !!}"
  29. @else
  30. --data "{!! addslashes(json_encode($endpoint->cleanBodyParameters, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)) !!}"
  31. @endif
  32. @endif
  33. ```