endpoint.blade.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. @include("scribe::partials.example-requests.$language")
  14. @endforeach
  15. </span>
  16. <span id="example-responses-{!! $endpoint->endpointId() !!}">
  17. @if($endpoint->isGet() || $endpoint->hasResponses())
  18. @foreach($endpoint->responses as $response)
  19. <blockquote>
  20. <p>Example response ({{$response->description ?: $response->status}}):</p>
  21. </blockquote>
  22. @if(count($response->headers))
  23. <details class="annotation">
  24. <summary>
  25. <small onclick="textContent = parentElement.parentElement.open ? 'Show headers' : 'Hide headers'">Show headers</small>
  26. </summary>
  27. <pre>
  28. <code class="language-http">@foreach($response->headers as $header => $value)
  29. {{ $header }}: {{ is_array($value) ? implode('; ', $value) : $value }}
  30. @endforeach </code>
  31. </pre>
  32. </details> @endif
  33. <pre>
  34. <code class="language-json">
  35. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  36. [Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}
  37. @elseif($response->status == 204)
  38. [Empty response]
  39. @else
  40. @php($parsed = json_decode($response->content))
  41. {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
  42. {!! htmlentities($parsed != null ? json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : $response->content) !!}
  43. @endif </code>
  44. </pre>
  45. @endforeach
  46. @endif
  47. </span>
  48. <span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  49. <blockquote>Received response<span
  50. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  51. </blockquote>
  52. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"></code></pre>
  53. </span>
  54. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  55. <blockquote>Request failed with error:</blockquote>
  56. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  57. </span>
  58. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  59. data-path="{{ $endpoint->uri }}"
  60. data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
  61. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  62. data-headers='@json($endpoint->headers)'
  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. 'endpointId' => $endpoint->endpointId(),
  109. 'component' => 'url',
  110. ])
  111. @endcomponent
  112. </p>
  113. @endforeach
  114. @endif
  115. @if(count($endpoint->queryParameters))
  116. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  117. @foreach($endpoint->queryParameters as $attribute => $parameter)
  118. <p>
  119. @component('scribe::components.field-details', [
  120. 'name' => $parameter->name,
  121. 'type' => $parameter->type,
  122. 'required' => $parameter->required,
  123. 'description' => $parameter->description,
  124. 'endpointId' => $endpoint->endpointId(),
  125. 'component' => 'query',
  126. ])
  127. @endcomponent
  128. </p>
  129. @endforeach
  130. @endif
  131. @if(count($endpoint->nestedBodyParameters))
  132. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  133. @component('scribe::components.body-parameters', ['parameters' => $endpoint->nestedBodyParameters, 'endpointId' => $endpoint->endpointId(),])
  134. @endcomponent
  135. @endif
  136. </form>
  137. @if(count($endpoint->responseFields))
  138. <h3>Response</h3>
  139. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  140. @foreach($endpoint->responseFields as $name => $field)
  141. <p>
  142. @component('scribe::components.field-details', [
  143. 'name' => $field->name,
  144. 'type' => $field->type,
  145. 'required' => true,
  146. 'description' => $field->description,
  147. 'isInput' => false,
  148. ])
  149. @endcomponent
  150. </p>
  151. @endforeach
  152. @endif