Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions assets/scripts/build-api-derefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ const processSpec = async (specPath) => {
const fileData = yaml.safeLoad(fs.readFileSync(specPath, 'utf8'));
const deref = await $RefParser.dereference(fileData, { resolve: { external: false } });

// VALIDATION: Ensure we actually have an object with servers
if (!deref || typeof deref !== 'object' || Array.isArray(deref)) {
throw new Error(`Deref produced invalid type: ${typeof deref}`);
}

const version = extractVersion(specPath);
if (!version) {
throw new Error(`Could not extract version from path: ${specPath}`);
}

// Write dereferenced JSON
const jsonString = safeJsonStringify(deref, null, 2);
// Safety check to prevent writing "null" or empty strings
if (jsonString === "null" || jsonString === '""' || jsonString.length < 5) {
throw new Error(`Aborting write: generated JSON for ${version} is suspiciously small or null.`);
}
const pathToJson = `./data/api/${version}/full_spec_deref.json`;
fs.writeFileSync(pathToJson, jsonString, 'utf8');
console.log(`Written dereferenced spec to: ${pathToJson}`);
Expand Down
12 changes: 6 additions & 6 deletions layouts/api/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@
{{ $versionCount := (len $menuChild.Params.versions) }}
<div class="row">
<div class="col-12 {{ if gt (len $menuChild.Params.versions) 0 }}col-md-6{{ end }}">
<h2 class="mb-2" id="{{ $anchorStr | anchorize }}">
<h2 class="mb-2 api-task-description" id="{{ $anchorStr | anchorize }}">
<a class="js-collapse-trigger" href="#{{ $anchorStr | anchorize }}">
{{- $anchorStr -}}
</a>
</h2>
</div>
{{ if gt (len $menuChild.Params.versions) 0 }}
<div class="col-12 col-md-6">
<div class="col-12 col-md-6 api-version-label-wrapper">
<ul class="nav nav-tabs response-toggle border-none justify-content-md-end">
{{ range $versionIndex, $versionNum := $menuChild.Params.versions }}
{{ $adat := cond (eq $versionNum "v1") $d $d2 }}
{{ $generalRegions := partial "api/regions.html" (dict "servers" $adat.servers) }}
{{ $endpoint := partial "api/get-endpoint.html" (dict "lang" $.Page.Lang "operationids" $menuChild.Params.operationids "spec" $adat "generalRegions" $generalRegions ) }}
{{ $endpointVisibility := partial "api/endpoint-visibility.html" (dict "versionCount" $versionCount "versionNum" $versionNum "menuChild" $menuChild "endpoint" $endpoint) }}
<li class="nav-item">
<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>
<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>
</li>
{{ end }}
</ul>
Expand Down Expand Up @@ -148,13 +148,13 @@ <h2 class="mb-2" id="{{ $anchorStr | anchorize }}">
</div>
{{ end }}

<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;
<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;
{{- range $region, $url := $endpoint.regions -}}
<span class="d-none" data-region="{{ $region }}">{{ $url }}{{ $endpoint.pathKey }}</span>
<span class="api-url-pattern d-none" data-region="{{ $region }}">{{ $url }}{{ $endpoint.pathKey }}</span>
{{- end -}}
{{- range $region, $url := $generalRegions -}}
{{- if not (index ($endpoint.regions) $region) -}}
<span class="d-none" data-region="{{ $region }}">Not supported in the {{ upper $region }} region</span>
<span class="api-url-pattern d-none" data-region="{{ $region }}">Not supported in the {{ upper $region }} region</span>
{{- end -}}
{{- end -}}
</p>
Expand Down
Loading