endpoint.blade.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. @php
  2. use Knuckles\Scribe\Tools\Utils as u;
  3. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  4. @endphp
  5. <h2 id="{!! $endpoint->fullSlug() !!}">{{ $endpoint->name() }}</h2>
  6. <p>
  7. @component('scribe::components.badges.auth', ['authenticated' => $endpoint->isAuthed()])
  8. @endcomponent
  9. </p>
  10. {!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!}
  11. <span id="example-requests-{!! $endpoint->endpointId() !!}">
  12. <blockquote>{{ u::trans("scribe::endpoint.example_request") }}:</blockquote>
  13. @foreach($metadata['example_languages'] as $language)
  14. <div class="{{ $language }}-example">
  15. @include("scribe::partials.example-requests.$language")
  16. </div>
  17. @endforeach
  18. </span>
  19. <span id="example-responses-{!! $endpoint->endpointId() !!}">
  20. @if($endpoint->isGet() || $endpoint->hasResponses())
  21. @foreach($endpoint->responses as $response)
  22. <blockquote>
  23. <p>{{ u::trans("scribe::endpoint.example_response") }} ({{ $response->fullDescription() }}):</p>
  24. </blockquote>
  25. @if(count($response->headers))
  26. <details class="annotation">
  27. <summary style="cursor: pointer;">
  28. <small onclick="textContent = parentElement.parentElement.open ? 'Show headers' : 'Hide headers'">Show headers</small>
  29. </summary>
  30. <pre><code class="language-http">@foreach($response->headers as $header => $value)
  31. {{ $header }}: {{ is_array($value) ? implode('; ', $value) : $value }}
  32. @endforeach </code></pre></details> @endif
  33. <pre>
  34. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  35. <code>{!! u::trans("scribe::endpoint.responses.binary") !!} - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
  36. @elseif($response->status == 204)
  37. <code>{!! u::trans("scribe::endpoint.responses.empty") !!}</code>
  38. @else
  39. @php($parsed = json_decode($response->content))
  40. {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
  41. <code class="language-json" style="max-height: 300px;">{!! htmlentities($parsed != null ? json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $response->content) !!}</code>
  42. @endif </pre>
  43. @endforeach
  44. @endif
  45. </span>
  46. <span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  47. <blockquote>{{ u::trans("scribe::try_it_out.received_response") }}<span
  48. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  49. </blockquote>
  50. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"
  51. data-empty-response-text="<{{ u::trans("scribe::endpoint.responses.empty") }}>" style="max-height: 400px;"></code></pre>
  52. </span>
  53. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  54. <blockquote>{{ u::trans("scribe::try_it_out.request_failed") }}:</blockquote>
  55. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}">{{ "\n\n".u::trans("scribe::try_it_out.error_help") }}</code></pre>
  56. </span>
  57. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  58. data-path="{{ $endpoint->uri }}"
  59. data-authed="{{ $endpoint->isAuthed() ? 1 : 0 }}"
  60. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  61. data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
  62. autocomplete="off"
  63. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  64. <h3>
  65. {{ u::trans("scribe::endpoint.request") }}&nbsp;&nbsp;&nbsp;
  66. @if($metadata['try_it_out']['enabled'] ?? false)
  67. <button type="button"
  68. style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  69. id="btn-tryout-{{ $endpoint->endpointId() }}"
  70. onclick="tryItOut('{{ $endpoint->endpointId() }}');">{{ u::trans("scribe::try_it_out.open") }}
  71. </button>
  72. <button type="button"
  73. style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  74. id="btn-canceltryout-{{ $endpoint->endpointId() }}"
  75. onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>{{ u::trans("scribe::try_it_out.cancel") }}
  76. </button>&nbsp;&nbsp;
  77. <button type="submit"
  78. style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  79. id="btn-executetryout-{{ $endpoint->endpointId() }}"
  80. data-initial-text="{{ u::trans("scribe::try_it_out.send") }}"
  81. data-loading-text="{{ u::trans("scribe::try_it_out.loading") }}"
  82. hidden>{{ u::trans("scribe::try_it_out.send") }}
  83. </button>
  84. @endif
  85. </h3>
  86. @foreach($endpoint->httpMethods as $method)
  87. <p>
  88. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  89. <b><code>{{$endpoint->uri}}</code></b>
  90. </p>
  91. @endforeach
  92. @if(count($endpoint->headers))
  93. <h4 class="fancy-heading-panel"><b>{{ u::trans("scribe::endpoint.headers") }}</b></h4>
  94. @foreach($endpoint->headers as $name => $example)
  95. <?php
  96. $htmlOptions = [];
  97. if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'header' && $metadata['auth']['name'] == $name) {
  98. $htmlOptions = [ 'class' => 'auth-value', ];
  99. }
  100. ?>
  101. <div style="padding-left: 28px; clear: unset;">
  102. @component('scribe::components.field-details', [
  103. 'name' => $name,
  104. 'type' => null,
  105. 'required' => true,
  106. 'description' => null,
  107. 'example' => $example,
  108. 'endpointId' => $endpoint->endpointId(),
  109. 'component' => 'header',
  110. 'isInput' => true,
  111. 'html' => $htmlOptions,
  112. ])
  113. @endcomponent
  114. </div>
  115. @endforeach
  116. @endif
  117. @if(count($endpoint->urlParameters))
  118. <h4 class="fancy-heading-panel"><b>{{ u::trans("scribe::endpoint.url_parameters") }}</b></h4>
  119. @foreach($endpoint->urlParameters as $attribute => $parameter)
  120. <div style="padding-left: 28px; clear: unset;">
  121. @component('scribe::components.field-details', [
  122. 'name' => $parameter->name,
  123. 'type' => $parameter->type ?? 'string',
  124. 'required' => $parameter->required,
  125. 'description' => $parameter->description,
  126. 'example' => $parameter->example ?? '',
  127. 'enumValues' => $parameter->enumValues,
  128. 'endpointId' => $endpoint->endpointId(),
  129. 'component' => 'url',
  130. 'isInput' => true,
  131. ])
  132. @endcomponent
  133. </div>
  134. @endforeach
  135. @endif
  136. @if(count($endpoint->queryParameters))
  137. <h4 class="fancy-heading-panel"><b>{{ u::trans("scribe::endpoint.query_parameters") }}</b></h4>
  138. @foreach($endpoint->queryParameters as $attribute => $parameter)
  139. <?php
  140. $htmlOptions = [];
  141. if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'query' && $metadata['auth']['name'] == $attribute) {
  142. $htmlOptions = [ 'class' => 'auth-value', ];
  143. }
  144. ?>
  145. <div style="padding-left: 28px; clear: unset;">
  146. @component('scribe::components.field-details', [
  147. 'name' => $parameter->name,
  148. 'type' => $parameter->type,
  149. 'required' => $parameter->required,
  150. 'description' => $parameter->description,
  151. 'example' => $parameter->example ?? '',
  152. 'enumValues' => $parameter->enumValues,
  153. 'endpointId' => $endpoint->endpointId(),
  154. 'component' => 'query',
  155. 'isInput' => true,
  156. 'html' => $htmlOptions,
  157. ])
  158. @endcomponent
  159. </div>
  160. @endforeach
  161. @endif
  162. @if(count($endpoint->nestedBodyParameters))
  163. <h4 class="fancy-heading-panel"><b>{{ u::trans("scribe::endpoint.body_parameters") }}</b></h4>
  164. <x-scribe::nested-fields
  165. :fields="$endpoint->nestedBodyParameters" :endpointId="$endpoint->endpointId()"
  166. />
  167. @endif
  168. </form>
  169. @if(count($endpoint->responseFields))
  170. <h3>{{ u::trans("scribe::endpoint.response") }}</h3>
  171. <h4 class="fancy-heading-panel"><b>{{ u::trans("scribe::endpoint.response_fields") }}</b></h4>
  172. <x-scribe::nested-fields
  173. :fields="$endpoint->nestedResponseFields" :endpointId="$endpoint->endpointId()"
  174. :isInput="false"
  175. />
  176. @endif