Skip to content
Merged
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
123 changes: 123 additions & 0 deletions src/pages/hcp/api-docs/vault/[[...page]].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

// View
import OpenApiDocsViewV2 from 'views/open-api-docs-view-v2'
import {
generateStaticPaths,
generateStaticPropsVersioned,
} from 'views/open-api-docs-view-v2/server'
// Utils
import { getOperationGroupKeyFromPath } from 'views/open-api-docs-view-v2/utils/get-operation-group-key-from-path'
// Schema transforms
import { schemaTransformShortenHcp } from 'views/open-api-docs-view-v2/schema-transforms/schema-transform-shorten-hcp'
import { schemaTransformComponent } from 'views/open-api-docs-view-v2/schema-transforms/schema-transform-component'
import { shortenProtobufAnyDescription } from 'views/open-api-docs-view-v2/schema-transforms/shorten-protobuf-any-description'
// Types
import type {
GetStaticPaths,
GetStaticProps,
GetStaticPropsContext,
} from 'next'
import type {
OpenApiDocsV2Params,
OpenApiDocsViewV2Props,
OpenApiDocsViewV2Config,
} from 'views/open-api-docs-view-v2/types'

/**
* Configure this OpenAPI spec page, specifying the source,
* and additional configuration that doesn't fit in the schema itself.
*/
const PAGE_CONFIG: OpenApiDocsViewV2Config = {
backToLink: {
href: '/hcp',
text: 'HashiCorp Cloud Platform',
},
basePath: '/hcp/api-docs/vault',
breadcrumbLinksPrefix: [
{
title: 'Developer',
url: '/',
},
{
title: 'HashiCorp Cloud Platform',
url: '/hcp',
},
],
schemaSource: {
owner: 'hashicorp',
repo: 'hcp-specs',
path: 'specs/cloud-vault-service',
ref: 'main',
},
productContext: 'hcp',
theme: 'vault',
getOperationGroupKey: getOperationGroupKeyFromPath,
resourceLinks: [
{
text: 'Tutorial Library',
href: '/tutorials/library?product=vault&edition=hcp',
},
{
text: 'Certifications',
href: '/certifications/security-automation',
},
{
text: 'Community',
href: 'https://discuss.hashicorp.com/',
},
{
text: 'Support',
href: 'https://www.hashicorp.com/customer-success',
},
],
schemaTransforms: [
// Replace "HashiCorp Cloud Platform" with "HCP" in the title
schemaTransformShortenHcp,
/**
* 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
*/
(schema) => {
return schemaTransformComponent(
schema,
'google.protobuf.Any',
shortenProtobufAnyDescription
)
},
],
}

/**
* Get static paths, using the configured `schemaSource`.
*/
export const getStaticPaths: GetStaticPaths<OpenApiDocsV2Params> = async () => {
return await generateStaticPaths({
schemaSource: PAGE_CONFIG.schemaSource,
schemaTransforms: PAGE_CONFIG.schemaTransforms,
})
}

/**
* Get static paths, using the configured `schemaSource`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated comment here from above, should say "get static props"

*/
export const getStaticProps: GetStaticProps<
OpenApiDocsViewV2Props,
OpenApiDocsV2Params
> = async ({ params }: GetStaticPropsContext<OpenApiDocsV2Params>) => {
return await generateStaticPropsVersioned(PAGE_CONFIG, params?.page)
}

export default OpenApiDocsViewV2
Loading