route.blade.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!-- START_{{$route['id']}} -->
  2. @if($route['title'] != '')## {{ $route['title']}}
  3. @else## {{$route['uri']}}@endif
  4. @if($route['authenticated'])
  5. <br><small style="padding: 1px 9px 2px;font-weight: bold;white-space: nowrap;color: #ffffff;-webkit-border-radius: 9px;-moz-border-radius: 9px;border-radius: 9px;background-color: #3a87ad;">Requires authentication</small>@endif
  6. @if($route['description'])
  7. {!! $route['description'] !!}
  8. @endif
  9. > Example request:
  10. ```bash
  11. curl -X {{$route['methods'][0]}} {{$route['methods'][0] == 'GET' ? '-G ' : ''}}"{{ trim(config('app.docs_url') ?: config('app.url'), '/')}}/{{ ltrim($route['boundUri'], '/') }}" @if(count($route['headers']))\
  12. @foreach($route['headers'] as $header => $value)
  13. -H "{{$header}}: {{$value}}"@if(! ($loop->last) || ($loop->last && count($route['bodyParameters']))) \
  14. @endif
  15. @endforeach
  16. @endif
  17. @if(count($route['cleanBodyParameters']))
  18. -d '{!! json_encode($route['cleanBodyParameters']) !!}'
  19. @endif
  20. ```
  21. ```javascript
  22. const url = new URL("{{ rtrim(config('app.docs_url') ?: config('app.url'), '/') }}/{{ ltrim($route['boundUri'], '/') }}");
  23. @if(count($route['queryParameters']))
  24. let params = {
  25. @foreach($route['queryParameters'] as $attribute => $parameter)
  26. "{{ $attribute }}": "{{ $parameter['value'] }}",
  27. @endforeach
  28. };
  29. Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
  30. @endif
  31. let headers = {
  32. @foreach($route['headers'] as $header => $value)
  33. "{{$header}}": "{{$value}}",
  34. @endforeach
  35. @if(!array_key_exists('Accept', $route['headers']))
  36. "Accept": "application/json",
  37. @endif
  38. @if(!array_key_exists('Content-Type', $route['headers']))
  39. "Content-Type": "application/json",
  40. @endif
  41. }
  42. @if(count($route['bodyParameters']))
  43. let body = {!! json_encode($route['cleanBodyParameters'], JSON_PRETTY_PRINT) !!}
  44. @endif
  45. fetch(url, {
  46. method: "{{$route['methods'][0]}}",
  47. headers: headers,
  48. @if(count($route['bodyParameters']))
  49. body: body
  50. @endif
  51. })
  52. .then(response => response.json())
  53. .then(json => console.log(json));
  54. ```
  55. @if(in_array('GET',$route['methods']) || (isset($route['showresponse']) && $route['showresponse']))
  56. @if(is_array($route['response']))
  57. @foreach($route['response'] as $response)
  58. > Example response ({{$response['status']}}):
  59. ```json
  60. @if(is_object($response['content']) || is_array($response['content']))
  61. {!! json_encode($response['content'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  62. @else
  63. {!! json_encode(json_decode($response['content']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  64. @endif
  65. ```
  66. @endforeach
  67. @else
  68. > Example response:
  69. ```json
  70. @if(is_object($route['response']) || is_array($route['response']))
  71. {!! json_encode($route['response'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  72. @else
  73. {!! json_encode(json_decode($route['response']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  74. @endif
  75. ```
  76. @endif
  77. @endif
  78. ### HTTP Request
  79. @foreach($route['methods'] as $method)
  80. `{{$method}} {{$route['uri']}}`
  81. @endforeach
  82. @if(count($route['bodyParameters']))
  83. #### Body Parameters
  84. Parameter | Type | Status | Description
  85. --------- | ------- | ------- | ------- | -----------
  86. @foreach($route['bodyParameters'] as $attribute => $parameter)
  87. {{$attribute}} | {{$parameter['type']}} | @if($parameter['required']) required @else optional @endif | {!! $parameter['description'] !!}
  88. @endforeach
  89. @endif
  90. @if(count($route['queryParameters']))
  91. #### Query Parameters
  92. Parameter | Status | Description
  93. --------- | ------- | ------- | -----------
  94. @foreach($route['queryParameters'] as $attribute => $parameter)
  95. {{$attribute}} | @if($parameter['required']) required @else optional @endif | {!! $parameter['description'] !!}
  96. @endforeach
  97. @endif
  98. <!-- END_{{$route['id']}} -->