Skip to content

Commit 0347908

Browse files
authored
add api classes again (#33613)
* add api classes * add some simple validation
1 parent 45e6fa0 commit 0347908

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

assets/scripts/build-api-derefs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ const processSpec = async (specPath) => {
4646
const fileData = yaml.safeLoad(fs.readFileSync(specPath, 'utf8'));
4747
const deref = await $RefParser.dereference(fileData, { resolve: { external: false } });
4848

49+
// VALIDATION: Ensure we actually have an object with servers
50+
if (!deref || typeof deref !== 'object' || Array.isArray(deref)) {
51+
throw new Error(`Deref produced invalid type: ${typeof deref}`);
52+
}
53+
4954
const version = extractVersion(specPath);
5055
if (!version) {
5156
throw new Error(`Could not extract version from path: ${specPath}`);
5257
}
5358

5459
// Write dereferenced JSON
5560
const jsonString = safeJsonStringify(deref, null, 2);
61+
// Safety check to prevent writing "null" or empty strings
62+
if (jsonString === "null" || jsonString === '""' || jsonString.length < 5) {
63+
throw new Error(`Aborting write: generated JSON for ${version} is suspiciously small or null.`);
64+
}
5665
const pathToJson = `./data/api/${version}/full_spec_deref.json`;
5766
fs.writeFileSync(pathToJson, jsonString, 'utf8');
5867
console.log(`Written dereferenced spec to: ${pathToJson}`);

layouts/api/list.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@
7474
{{ $versionCount := (len $menuChild.Params.versions) }}
7575
<div class="row">
7676
<div class="col-12 {{ if gt (len $menuChild.Params.versions) 0 }}col-md-6{{ end }}">
77-
<h2 class="mb-2" id="{{ $anchorStr | anchorize }}">
77+
<h2 class="mb-2 api-task-description" id="{{ $anchorStr | anchorize }}">
7878
<a class="js-collapse-trigger" href="#{{ $anchorStr | anchorize }}">
7979
{{- $anchorStr -}}
8080
</a>
8181
</h2>
8282
</div>
8383
{{ if gt (len $menuChild.Params.versions) 0 }}
84-
<div class="col-12 col-md-6">
84+
<div class="col-12 col-md-6 api-version-label-wrapper">
8585
<ul class="nav nav-tabs response-toggle border-none justify-content-md-end">
8686
{{ range $versionIndex, $versionNum := $menuChild.Params.versions }}
8787
{{ $adat := cond (eq $versionNum "v1") $d $d2 }}
8888
{{ $generalRegions := partial "api/regions.html" (dict "servers" $adat.servers) }}
8989
{{ $endpoint := partial "api/get-endpoint.html" (dict "lang" $.Page.Lang "operationids" $menuChild.Params.operationids "spec" $adat "generalRegions" $generalRegions ) }}
9090
{{ $endpointVisibility := partial "api/endpoint-visibility.html" (dict "versionCount" $versionCount "versionNum" $versionNum "menuChild" $menuChild "endpoint" $endpoint) }}
9191
<li class="nav-item">
92-
<a class="nav-link me-1 {{ with $endpointVisibility.label }}{{ else }}px-3{{ end }} {{ if and ($endpointVisibility.isVisibleVersion) (gt (len $menuChild.Params.versions) 1) }}active{{ end }} {{ if and ($endpointVisibility.isVisibleVersion) (eq (len $menuChild.Params.versions) 1) }}disabled{{ end }}" {{- if and (eq (len $menuChild.Params.versions) 1) ($endpoint.action.deprecated | default false) -}}data-bs-toggle="collapse"{{- else -}}data-bs-toggle="tab" data-bs-target="#{{ (print $anchorStr "-" $versionNum) | anchorize }}"{{- end -}} href="#{{ (print $anchorStr "-" $versionNum) | anchorize }}">{{ $versionNum }} {{ with $endpointVisibility.label }}({{ . }}){{ end }}</a>
92+
<a class="nav-link me-1 api-version-label {{ with $endpointVisibility.label }}{{ else }}px-3{{ end }} {{ if and ($endpointVisibility.isVisibleVersion) (gt (len $menuChild.Params.versions) 1) }}active{{ end }} {{ if and ($endpointVisibility.isVisibleVersion) (eq (len $menuChild.Params.versions) 1) }}disabled{{ end }}" {{- if and (eq (len $menuChild.Params.versions) 1) ($endpoint.action.deprecated | default false) -}}data-bs-toggle="collapse"{{- else -}}data-bs-toggle="tab" data-bs-target="#{{ (print $anchorStr "-" $versionNum) | anchorize }}"{{- end -}} href="#{{ (print $anchorStr "-" $versionNum) | anchorize }}">{{ $versionNum }} {{ with $endpointVisibility.label }}({{ . }}){{ end }}</a>
9393
</li>
9494
{{ end }}
9595
</ul>
@@ -148,13 +148,13 @@ <h2 class="mb-2" id="{{ $anchorStr | anchorize }}">
148148
</div>
149149
{{ end }}
150150

151-
<p class="mb-0"><span style="padding: 3px" class="font-semibold text-api-{{ $endpoint.actionType }} bg-bg-api-{{ $endpoint.actionType }}">{{ $endpoint.actionType | upper }}</span>&nbsp;
151+
<p class="mb-0 api-url-info"><span style="padding: 3px" class="font-semibold api-method text-api-method text-api-{{ $endpoint.actionType }} bg-bg-api-{{ $endpoint.actionType }}">{{ $endpoint.actionType | upper }}</span>&nbsp;
152152
{{- range $region, $url := $endpoint.regions -}}
153-
<span class="d-none" data-region="{{ $region }}">{{ $url }}{{ $endpoint.pathKey }}</span>
153+
<span class="api-url-pattern d-none" data-region="{{ $region }}">{{ $url }}{{ $endpoint.pathKey }}</span>
154154
{{- end -}}
155155
{{- range $region, $url := $generalRegions -}}
156156
{{- if not (index ($endpoint.regions) $region) -}}
157-
<span class="d-none" data-region="{{ $region }}">Not supported in the {{ upper $region }} region</span>
157+
<span class="api-url-pattern d-none" data-region="{{ $region }}">Not supported in the {{ upper $region }} region</span>
158158
{{- end -}}
159159
{{- end -}}
160160
</p>

0 commit comments

Comments
 (0)