endpoint.blade.php 7.3 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><code class="language-http">@foreach($response->headers as $header => $value)
  28. {{ $header }}: {{ is_array($value) ? implode('; ', $value) : $value }}
  29. @endforeach </code></pre>
  30. </details> @endif
  31. <pre>
  32. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  33. <code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
  34. @elseif($response->status == 204)
  35. <code>[Empty response]</code>
  36. @else
  37. @php($parsed = json_decode($response->content))
  38. {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
  39. <code class="language-json">{!! htmlentities($parsed != null ? json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $response->content) !!}</code>
  40. @endif </pre>
  41. @endforeach
  42. @endif
  43. </span>
  44. <span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  45. <blockquote>Received response<span
  46. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  47. </blockquote>
  48. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"></code></pre>
  49. </span>
  50. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  51. <blockquote>Request failed with error:</blockquote>
  52. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  53. </span>
  54. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  55. data-path="{{ $endpoint->uri }}"
  56. data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
  57. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  58. data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
  59. data-headers='@json($endpoint->headers)'
  60. autocomplete="off"
  61. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  62. <h3>
  63. Request&nbsp;&nbsp;&nbsp;
  64. @if($metadata['try_it_out']['enabled'] ?? false)
  65. <button type="button"
  66. style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  67. id="btn-tryout-{{ $endpoint->endpointId() }}"
  68. onclick="tryItOut('{{ $endpoint->endpointId() }}');">Try it out ⚡
  69. </button>
  70. <button type="button"
  71. style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  72. id="btn-canceltryout-{{ $endpoint->endpointId() }}"
  73. onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>Cancel 🛑
  74. </button>&nbsp;&nbsp;
  75. <button type="submit"
  76. style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  77. id="btn-executetryout-{{ $endpoint->endpointId() }}" hidden>Send Request 💥
  78. </button>
  79. @endif
  80. </h3>
  81. @foreach($endpoint->httpMethods as $method)
  82. <p>
  83. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  84. <b><code>{{$endpoint->uri}}</code></b>
  85. </p>
  86. @endforeach
  87. @if($endpoint->metadata->authenticated && $metadata['auth']['location'] === 'header')
  88. <p>
  89. <label id="auth-{{ $endpoint->endpointId() }}" hidden>{{ $metadata['auth']['name'] }} header:
  90. <b><code>{{ $metadata['auth']['prefix'] }}</code></b><input type="text"
  91. name="{{ $metadata['auth']['name'] }}"
  92. data-prefix="{{ $metadata['auth']['prefix'] }}"
  93. data-endpoint="{{ $endpoint->endpointId() }}"
  94. data-component="header"></label>
  95. </p>
  96. @endif
  97. @if(count($endpoint->urlParameters))
  98. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  99. @foreach($endpoint->urlParameters as $attribute => $parameter)
  100. <p>
  101. @component('scribe::components.field-details', [
  102. 'name' => $parameter->name,
  103. 'type' => $parameter->type ?? 'string',
  104. 'required' => $parameter->required,
  105. 'description' => $parameter->description,
  106. 'example' => $parameter->example ?? '',
  107. 'endpointId' => $endpoint->endpointId(),
  108. 'component' => 'url',
  109. ])
  110. @endcomponent
  111. </p>
  112. @endforeach
  113. @endif
  114. @if(count($endpoint->queryParameters))
  115. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  116. @foreach($endpoint->queryParameters as $attribute => $parameter)
  117. <p>
  118. @component('scribe::components.field-details', [
  119. 'name' => $parameter->name,
  120. 'type' => $parameter->type,
  121. 'required' => $parameter->required,
  122. 'description' => $parameter->description,
  123. 'example' => $parameter->example ?? '',
  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