endpoint.blade.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. @php
  2. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  3. @endphp
  4. <h2 id="{!! Str::slug($group['name']) !!}-{!! $endpoint->endpointId() !!}">{{ $endpoint->metadata->title ?: $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. <blockquote>Example request:</blockquote>
  11. @foreach($metadata['example_languages'] as $language)
  12. @include("scribe::partials.example-requests.$language")
  13. @endforeach
  14. @if($endpoint->isGet() || $endpoint->hasResponses())
  15. @foreach($endpoint->responses as $response)
  16. <blockquote>
  17. <p>Example response ({{$response->description ?: $response->status}}):</p>
  18. </blockquote>
  19. @if(count($response->headers))
  20. <details class="annotation">
  21. <summary onclick="textContent = parentElement.open ? 'Show headers ▼' : 'Hide headers ▲'">
  22. Show headers ▼
  23. </summary>
  24. <pre>
  25. <code class="language-http">@foreach($response->headers as $header => $values)
  26. {{ $header }}: {{ implode('; ', $values) }}
  27. @endforeach </code>
  28. </pre>
  29. </details> @endif
  30. <pre>
  31. <code class="language-json">
  32. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  33. [Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}
  34. @elseif($response->status == 204)
  35. [Empty response]
  36. @elseif(is_string($response->content) && json_decode($response->content) == null && $response->content !== null)
  37. {{-- If response is a non-JSON string, just print it --}}
  38. {!! htmlentities($response->content) !!}
  39. @else
  40. {!! htmlentities(json_encode(json_decode($response->content), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)) !!}
  41. @endif </code>
  42. </pre>
  43. @endforeach
  44. @endif
  45. <div id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  46. <blockquote>Received response<span
  47. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  48. </blockquote>
  49. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"></code></pre>
  50. </div>
  51. <div id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  52. <blockquote>Request failed with error:</blockquote>
  53. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  54. </div>
  55. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->methods[0] }}"
  56. data-path="{{ $endpoint->uri }}"
  57. data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
  58. data-hasfiles="{{ $endpoint->hasFiles() }}"
  59. data-headers='@json($endpoint->headers)'
  60. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  61. <h3>
  62. Request&nbsp;&nbsp;&nbsp;
  63. @if($metadata['interactive'])
  64. <button type="button"
  65. style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  66. id="btn-tryout-{{ $endpoint->endpointId() }}"
  67. onclick="tryItOut('{{ $endpoint->endpointId() }}');">Try it out ⚡
  68. </button>
  69. <button type="button"
  70. style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  71. id="btn-canceltryout-{{ $endpoint->endpointId() }}"
  72. onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>Cancel
  73. </button>&nbsp;&nbsp;
  74. <button type="submit"
  75. style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  76. id="btn-executetryout-{{ $endpoint->endpointId() }}" hidden>Send Request 💥
  77. </button>
  78. @endif
  79. </h3>
  80. @foreach($endpoint->methods as $method)
  81. <p>
  82. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  83. <b><code>{{$endpoint->uri}}</code></b>
  84. </p>
  85. @endforeach
  86. @if($endpoint->metadata->authenticated && $metadata['auth']['location'] === 'header')
  87. <p>
  88. <label id="auth-{{ $endpoint->endpointId() }}" hidden>{{ $metadata['auth']['name'] }} header:
  89. <b><code>{{ $metadata['auth']['prefix'] }}</code></b><input type="text"
  90. name="{{ $metadata['auth']['name'] }}"
  91. data-prefix="{{ $metadata['auth']['prefix'] }}"
  92. data-endpoint="{{ $endpoint->endpointId() }}"
  93. data-component="header"></label>
  94. </p>
  95. @endif
  96. @if(count($endpoint->urlParameters))
  97. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  98. @foreach($endpoint->urlParameters as $attribute => $parameter)
  99. <p>
  100. @component('scribe::components.field-details', [
  101. 'name' => $parameter->name,
  102. 'type' => $parameter->type ?? 'string',
  103. 'required' => $parameter->required,
  104. 'description' => $parameter->description,
  105. 'endpointId' => $endpoint->endpointId(),
  106. 'component' => 'url',
  107. ])
  108. @endcomponent
  109. </p>
  110. @endforeach
  111. @endif
  112. @if(count($endpoint->queryParameters))
  113. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  114. @foreach($endpoint->queryParameters as $attribute => $parameter)
  115. <p>
  116. @component('scribe::components.field-details', [
  117. 'name' => $parameter->name,
  118. 'type' => $parameter->type,
  119. 'required' => $parameter->required,
  120. 'description' => $parameter->description,
  121. 'endpointId' => $endpoint->endpointId(),
  122. 'component' => 'query',
  123. ])
  124. @endcomponent
  125. </p>
  126. @endforeach
  127. @endif
  128. @if(count($endpoint->nestedBodyParameters))
  129. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  130. @component('scribe::components.body-parameters', ['parameters' => $endpoint->nestedBodyParameters, 'endpointId' => $endpoint->endpointId(),])
  131. @endcomponent
  132. @endif
  133. </form>
  134. @if(count($endpoint->responseFields))
  135. <h3>Response</h3>
  136. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  137. @foreach($endpoint->responseFields as $name => $field)
  138. <p>
  139. @component('scribe::components.field-details', [
  140. 'name' => $field->name,
  141. 'type' => $field->type,
  142. 'required' => true,
  143. 'description' => $field->description,
  144. 'isInput' => false,
  145. ])
  146. @endcomponent
  147. </p>
  148. @endforeach
  149. @endif