1{{--
2 Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
3 See the LICENCE file in the repository root for full licence text.
4--}}
5@php
6 /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
7 use App\Libraries\ApidocRouteHelper;
8
9 $uri = $endpoint->uri;
10 $methods = $endpoint->httpMethods;
11 $descriptions = explode("\n---\n", $endpoint->metadata->description ?? '');
12
13 $topDescription = $descriptions[0];
14 $bottomDescription = $descriptions[1] ?? '';
15
16 $isApiUri = substr($uri, 0, 6) === 'api/v2';
17 // either remove api/v2 prefix or add full url
18 $displayUri = $isApiUri ? substr($uri, 6) : $GLOBALS['cfg']['app']['url'].$uri;
19
20 $helper = ApidocRouteHelper::instance();
21@endphp
22
23@if ($showEndpointTitle ?? true)
24<h2 id="{!! $endpoint->fullSlug() !!}">{{ $endpoint->name() }}</h2>
25@endif
26
27@if ($isApiUri)
28<p>
29 @if ($helper->getAuth($methods, $uri))
30 <a href="#resource-owner" class="badge badge-scope badge-user">requires user</a>
31 @endif
32
33 @foreach($helper->getScopeTags($methods, $uri) as $scope)
34 {{ ApidocRouteHelper::scopeBadge($scope) }}
35 @endforeach
36</p>
37@endif
38
39{!! Parsedown::instance()->text($topDescription) !!}
40
41<span id="example-requests-{!! $endpoint->endpointId() !!}">
42<blockquote>Example request:</blockquote>
43
44@foreach($metadata['example_languages'] as $language)
45
46<div class="{{ $language }}-example">
47 @include("scribe::partials.example-requests.$language")
48</div>
49
50@endforeach
51</span>
52
53<span id="example-responses-{!! $endpoint->endpointId() !!}">
54@if($endpoint->isGet() || $endpoint->hasResponses())
55 @foreach($endpoint->responses as $response)
56 <blockquote>
57 <p>Example response ({{ $response->fullDescription() }}):</p>
58 </blockquote>
59 @if(count($response->headers))
60 <details class="annotation">
61 <summary style="cursor: pointer;">
62 <small onclick="textContent = parentElement.parentElement.open ? 'Show headers' : 'Hide headers'">Show headers</small>
63 </summary>
64 <pre><code class="language-http">@foreach($response->headers as $header => $value)
65{{ $header }}: {{ is_array($value) ? implode('; ', $value) : $value }}
66@endforeach </code></pre></details> @endif
67 <pre>@if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
68<code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
69@elseif($response->status == 204)
70<code>[Empty response]</code>
71@else
72@php($parsed = json_decode($response->content))
73{{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
74<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>
75@endif </pre>
76 @endforeach
77@endif
78</span>
79<span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
80 <blockquote>Received response<span
81 id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
82 </blockquote>
83 <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}" style="max-height: 400px;"></code></pre>
84</span>
85<span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
86 <blockquote>Request failed with error:</blockquote>
87 <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
88</span>
89@if ($showRequestTitle ?? true)
90<h3>Request</h3>
91@endif
92@foreach($endpoint->httpMethods as $method)
93 <p>
94 @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
95 <b><code>{{ $displayUri }}</code></b>
96 </p>
97@endforeach
98<form>
99@if(count($endpoint->headers))
100 <h4 class="fancy-heading-panel"><b>Headers</b></h4>
101 @foreach($endpoint->headers as $name => $example)
102 <?php
103 $htmlOptions = [];
104 if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'header' && $metadata['auth']['name'] == $name) {
105 $htmlOptions = [ 'class' => 'auth-value', ];
106 }
107 ?>
108 <div style="padding-left: 28px; clear: unset;">
109 @component('scribe::components.field-details', [
110 'name' => $name,
111 'type' => null,
112 'required' => true,
113 'description' => null,
114 'example' => $example,
115 'endpointId' => $endpoint->endpointId(),
116 'component' => 'header',
117 'isInput' => true,
118 'html' => $htmlOptions,
119 ])
120 @endcomponent
121 </div>
122 @endforeach
123@endif
124@if(count($endpoint->urlParameters))
125 <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
126 @foreach($endpoint->urlParameters as $attribute => $parameter)
127 <div style="padding-left: 28px; clear: unset;">
128 @component('scribe::components.field-details', [
129 'name' => $parameter->name,
130 'type' => $parameter->type ?? 'string',
131 'required' => $parameter->required,
132 'description' => $parameter->description,
133 // TODO: show correct example (from $parameter->example)
134 'example' => '',
135 'endpointId' => $endpoint->endpointId(),
136 'component' => 'url',
137 'isInput' => true,
138 ])
139 @endcomponent
140 </div>
141 @endforeach
142@endif
143@if(count($endpoint->queryParameters))
144 <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
145 @foreach($endpoint->queryParameters as $attribute => $parameter)
146 <?php
147 $htmlOptions = [];
148 if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'query' && $metadata['auth']['name'] == $attribute) {
149 $htmlOptions = [ 'class' => 'auth-value', ];
150 }
151 ?>
152 <div style="padding-left: 28px; clear: unset;">
153 @component('scribe::components.field-details', [
154 'name' => $parameter->name,
155 'type' => $parameter->type,
156 'required' => $parameter->required,
157 'description' => $parameter->description,
158 // TODO: show correct example (from $parameter->example)
159 'example' => '',
160 'endpointId' => $endpoint->endpointId(),
161 'component' => 'query',
162 'isInput' => true,
163 'html' => $htmlOptions,
164 ])
165 @endcomponent
166 </div>
167 @endforeach
168@endif
169@if(count($endpoint->nestedBodyParameters))
170 <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
171 <x-docs.nested-fields
172 :fields="$endpoint->nestedBodyParameters" :endpointId="$endpoint->endpointId()"
173 />
174@endif
175</form>
176
177@if(count($endpoint->responseFields))
178 <h3>Response</h3>
179 <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
180 <x-docs.nested-fields
181 :fields="$endpoint->nestedResponseFields" :endpointId="$endpoint->endpointId()"
182 :isInput="false"
183 />
184@endif
185
186{!! Parsedown::instance()->text($bottomDescription) !!}