endpoint.blade.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. @php
  2. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  3. @endphp
  4. <h2 id="{!! Str::slug($group['name']) !!}-{!! $endpoint->endpointId() !!}">{{ $endpoint->metadata->title ?: ($endpoint->httpMethods[0]." ".$endpoint->uri)}}</h2>
  5. <p>
  6. @component('scribe::components.badges.auth', ['authenticated' => $endpoint->metadata->authenticated])
  7. @endcomponent
  8. </p>
  9. {!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!}
  10. <span id="example-requests-{!! $endpoint->endpointId() !!}">
  11. <blockquote>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>Example response ({{$response->description ?: $response->status}}):</p>
  23. </blockquote>
  24. @if(count($response->headers))
  25. <details class="annotation">
  26. <summary>
  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>
  32. </details> @endif
  33. <pre>
  34. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  35. <code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
  36. @elseif($response->status == 204)
  37. <code>[Empty response]</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">{!! 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>Received response<span
  48. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  49. </blockquote>
  50. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"></code></pre>
  51. </span>
  52. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  53. <blockquote>Request failed with error:</blockquote>
  54. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  55. </span>
  56. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  57. data-path="{{ $endpoint->uri }}"
  58. data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
  59. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  60. data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
  61. data-headers='@json($endpoint->headers)'
  62. autocomplete="off"
  63. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  64. <h3>
  65. 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() }}');">Try it out ⚡
  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>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() }}" hidden>Send Request 💥
  80. </button>
  81. @endif
  82. </h3>
  83. @foreach($endpoint->httpMethods as $method)
  84. <p>
  85. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  86. <b><code>{{$endpoint->uri}}</code></b>
  87. </p>
  88. @endforeach
  89. @if($endpoint->metadata->authenticated && $metadata['auth']['location'] === 'header')
  90. <p>
  91. <label id="auth-{{ $endpoint->endpointId() }}" hidden>{{ $metadata['auth']['name'] }} header:
  92. <b><code>{{ $metadata['auth']['prefix'] }}</code></b><input type="text"
  93. name="{{ $metadata['auth']['name'] }}"
  94. data-prefix="{{ $metadata['auth']['prefix'] }}"
  95. data-endpoint="{{ $endpoint->endpointId() }}"
  96. data-component="header"></label>
  97. </p>
  98. @endif
  99. @if(count($endpoint->urlParameters))
  100. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  101. @foreach($endpoint->urlParameters as $attribute => $parameter)
  102. <p>
  103. @component('scribe::components.field-details', [
  104. 'name' => $parameter->name,
  105. 'type' => $parameter->type ?? 'string',
  106. 'required' => $parameter->required,
  107. 'description' => $parameter->description,
  108. 'example' => $parameter->example ?? '',
  109. 'endpointId' => $endpoint->endpointId(),
  110. 'component' => 'url',
  111. ])
  112. @endcomponent
  113. </p>
  114. @endforeach
  115. @endif
  116. @if(count($endpoint->queryParameters))
  117. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  118. @foreach($endpoint->queryParameters as $attribute => $parameter)
  119. <p>
  120. @component('scribe::components.field-details', [
  121. 'name' => $parameter->name,
  122. 'type' => $parameter->type,
  123. 'required' => $parameter->required,
  124. 'description' => $parameter->description,
  125. 'example' => $parameter->example ?? '',
  126. 'endpointId' => $endpoint->endpointId(),
  127. 'component' => 'query',
  128. ])
  129. @endcomponent
  130. </p>
  131. @endforeach
  132. @endif
  133. @if(count($endpoint->nestedBodyParameters))
  134. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  135. @component('scribe::components.body-parameters', ['parameters' => $endpoint->nestedBodyParameters, 'endpointId' => $endpoint->endpointId(),])
  136. @endcomponent
  137. @endif
  138. </form>
  139. @if(count($endpoint->responseFields))
  140. <h3>Response</h3>
  141. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  142. @foreach($endpoint->responseFields as $name => $field)
  143. <p>
  144. @component('scribe::components.field-details', [
  145. 'name' => $field->name,
  146. 'type' => $field->type,
  147. 'required' => true,
  148. 'description' => $field->description,
  149. 'isInput' => false,
  150. ])
  151. @endcomponent
  152. </p>
  153. @endforeach
  154. @endif