endpoint.blade.php 8.4 KB

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