From 3fe91ee4a9d90605df2ef35fc9b61d2ec3515a84 Mon Sep 17 00:00:00 2001 From: Zach Shilton <4624598+zchsh@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:05:35 -0400 Subject: [PATCH] add HCP Vagrant Box Registry API docs --- .../vagrant-box-registry/[[...page]].tsx | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx diff --git a/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx b/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx new file mode 100644 index 0000000000..49ccadbec4 --- /dev/null +++ b/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx @@ -0,0 +1,118 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +// Lib +import { fetchCloudApiVersionData } from 'lib/api-docs/fetch-cloud-api-version-data' +// View +import OpenApiDocsView from 'views/open-api-docs-view' +import { + getStaticPaths, + getStaticProps as getOpenApiDocsStaticProps, +} from 'views/open-api-docs-view/server' +// Types +import type { GetStaticProps, GetStaticPropsContext } from 'next' +import type { OpenAPIV3 } from 'openapi-types' +import type { + OpenApiDocsParams, + OpenApiDocsViewProps, + OpenApiDocsPageConfig, +} from 'views/open-api-docs-view/types' +import { + schemaModShortenHcp, + schemaModComponent, + shortenProtobufAnyDescription, +} from 'views/open-api-docs-view/utils/massage-schema-utils' + +/** + * OpenApiDocsView server-side page configuration + */ +const PAGE_CONFIG: OpenApiDocsPageConfig = { + productSlug: 'hcp', + serviceProductSlug: 'vagrant', + basePath: '/hcp/api-docs/vagrant-box-registry', + githubSourceDirectory: { + owner: 'hashicorp', + repo: 'hcp-specs', + path: 'specs/cloud-vagrant-box-registry', + ref: 'main', + }, + groupOperationsByPath: true, + statusIndicatorConfig: { + pageUrl: 'https://status.hashicorp.com', + endpointUrl: + 'https://status.hashicorp.com/api/v2/components/1mdm36t0fkx1.json', + }, + navResourceItems: [ + { + title: 'Tutorial Library', + href: '/tutorials/library?product=vagrant', + }, + { + title: 'Community', + href: 'https://discuss.hashicorp.com/', + }, + { + title: 'Support', + href: 'https://www.hashicorp.com/customer-success', + }, + ], + + /** + * Massage the schema data a little bit + */ + massageSchemaForClient: (schemaData: OpenAPIV3.Document) => { + // Replace "HashiCorp Cloud Platform" with "HCP" in the title + const withShortTitle = schemaModShortenHcp(schemaData) + /** + * Shorten the description of the protobufAny schema + * + * Note: ideally this would be done at the content source, + * but until we've got that work done, this shortening + * seems necessary to ensure incremental static regeneration works + * for past versions of the API docs. Without this shortening, + * it seems the response size ends up crossing a threshold that + * causes the serverless function that renders the page to fail. + * + * Related task: + * https://app.asana.com/0/1207339219333499/1207339701271604/f + */ + const withShortProtobufDocs = schemaModComponent( + withShortTitle, + 'google.protobuf.Any', + shortenProtobufAnyDescription + ) + // Return the schema data with modifications + return withShortProtobufDocs + }, +} + +/** + * Get static paths, using `versionData` fetched from GitHub. + */ +export { getStaticPaths } + +/** + * Get static props, using `versionData` fetched from GitHub. + * + * We need all version data for the version selector, + * and of course we need specific data for the current version. + */ +export const getStaticProps: GetStaticProps< + OpenApiDocsViewProps, + OpenApiDocsParams +> = async ({ params }: GetStaticPropsContext) => { + // Fetch all version data, based on remote `stable` & `preview` subfolders + const versionData = await fetchCloudApiVersionData( + PAGE_CONFIG.githubSourceDirectory + ) + // Generate static props based on page configuration, params, and versionData + return await getOpenApiDocsStaticProps({ + ...PAGE_CONFIG, + context: { params }, + versionData, + }) +} + +export default OpenApiDocsView