Skip to content

Commit 6fe67e6

Browse files
authored
chore(openapi): fix up duplicate VersionData types (#2182)
* chore: rename to sourceFile in ApiDocsVersionData * chore: rm duplicate OpenApiDocsVersionData * fix: old type import * fix: finish sourceFile rename
1 parent e94df40 commit 6fe67e6

File tree

16 files changed

+47
-85
lines changed

16 files changed

+47
-85
lines changed

src/lib/api-docs/fetch-cloud-api-version-data/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ async function fetchCloudApiVersionData(
5353
// Construct the version metadata needed to fetch static props
5454
const versionId = versionIdFromPath(filePathFromRepoRoot)
5555
const releaseStage = releaseStageFromPath(filePathFromRepoRoot)
56-
const targetFile = {
56+
const sourceFile = {
5757
owner: githubDir.owner,
5858
repo: githubDir.repo,
5959
path: filePathFromRepoRoot,
6060
ref: githubDir.ref,
6161
}
62-
return { versionId, releaseStage, targetFile }
62+
return { versionId, releaseStage, sourceFile }
6363
})
6464
// Return the version data, sorted in descending order
6565
return sortDateVersionData(versionData)

src/lib/api-docs/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export interface ApiDocsVersionData {
1414
// The release stage of this version of the API docs
1515
releaseStage?: string // typically 'stable' | 'preview'
1616
// The schema file we'll load and render into the page for this version
17-
targetFile: GithubFile | string
17+
sourceFile: GithubFile | string
1818
}

src/pages/boundary/api-docs/[[...page]].tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import {
1313
ApiDocsParams,
1414
} from 'views/api-docs-view/server'
1515
// Types
16-
import type {
17-
ApiDocsVersionData,
18-
ApiDocsViewProps,
19-
} from 'views/api-docs-view/types'
16+
import type { ApiDocsVersionData } from 'lib/api-docs/types'
17+
import type { ApiDocsViewProps } from 'views/api-docs-view/types'
2018
import type { GetStaticPaths, GetStaticProps } from 'next'
2119

2220
/**
@@ -41,7 +39,7 @@ const TARGET_LOCAL_FILE = '../../internal/gen/controller.swagger.json'
4139
* version data from elsewhere, as we do for `/hcp/api-docs/packer`.
4240
*/
4341
function getVersionData(): ApiDocsVersionData[] {
44-
const targetFile = isDeployPreview(PRODUCT_SLUG)
42+
const sourceFile = isDeployPreview(PRODUCT_SLUG)
4543
? TARGET_LOCAL_FILE
4644
: {
4745
owner: 'hashicorp',
@@ -59,7 +57,7 @@ function getVersionData(): ApiDocsVersionData[] {
5957
* That might better align with versioned API docs for Boundary.
6058
*/
6159
versionId: 'latest',
62-
targetFile,
60+
sourceFile,
6361
},
6462
]
6563
}

src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,11 @@ export const getStaticProps: GetStaticProps<
9898
}
9999

100100
return await getOpenApiDocsStaticProps({
101-
basePath: PAGE_CONFIG.basePath,
102-
productSlug: PAGE_CONFIG.productSlug,
103-
serviceProductSlug: PAGE_CONFIG.serviceProductSlug,
104-
statusIndicatorConfig: PAGE_CONFIG.statusIndicatorConfig,
105-
navResourceItems: PAGE_CONFIG.navResourceItems,
106-
groupOperationsByPath: PAGE_CONFIG.groupOperationsByPath,
107-
massageSchemaForClient: PAGE_CONFIG.massageSchemaForClient,
108-
// Pass params to getStaticProps, this is used for versioning
101+
// Pass page configuration
102+
...PAGE_CONFIG,
103+
// Pass context and versionData to getStaticProps, needed for versioning
109104
context: { params },
110-
// Handle rename of `targetFile` to `sourceFile` for new template
111-
versionData: versionData.map(({ targetFile, ...rest }) => {
112-
return { ...rest, sourceFile: targetFile }
113-
}),
105+
versionData,
114106
})
115107
}
116108

src/pages/waypoint/api-docs/[[...page]].tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import {
1313
ApiDocsParams,
1414
} from 'views/api-docs-view/server'
1515
// Components
16-
import type {
17-
ApiDocsVersionData,
18-
ApiDocsViewProps,
19-
} from 'views/api-docs-view/types'
16+
import type { ApiDocsVersionData } from 'lib/api-docs/types'
17+
import type { ApiDocsViewProps } from 'views/api-docs-view/types'
2018
import type { GetStaticPaths, GetStaticProps } from 'next'
2119
import { buildApiDocsBreadcrumbs } from 'views/api-docs-view/server/get-api-docs-static-props/utils'
2220
import {
@@ -57,7 +55,7 @@ const MAY_HAVE_CIRCULAR_REFERENCES = true
5755
* version data from elsewhere, as we do for `/hcp/api-docs/packer`.
5856
*/
5957
function getVersionData(): ApiDocsVersionData[] {
60-
const targetFile = isDeployPreview(PRODUCT_SLUG)
58+
const sourceFile = isDeployPreview(PRODUCT_SLUG)
6159
? TARGET_LOCAL_FILE
6260
: {
6361
owner: 'hashicorp',
@@ -75,7 +73,7 @@ function getVersionData(): ApiDocsVersionData[] {
7573
* That might better align with versioned API docs for Waypoint.
7674
*/
7775
versionId: 'latest',
78-
targetFile,
76+
sourceFile,
7977
},
8078
]
8179
}

src/views/api-docs-view/components/api-docs-version-alert/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
import type { ApiDocsVersionData } from 'views/api-docs-view/types'
6+
import type { ApiDocsVersionData } from 'lib/api-docs/types'
77

88
export interface ApiDocsVersionAlertProps {
99
isVersionedUrl: boolean

src/views/api-docs-view/server/get-api-docs-static-paths/fetch-api-docs-paths.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
import type { GithubFile } from 'lib/fetch-github-file'
1818

1919
/**
20-
* Given a `targetFile` pointing to a valid OpenAPI Swagger `.json` file,
20+
* Given a `sourceFile` pointing to a valid OpenAPI Swagger `.json` file,
2121
*
2222
* Return an array of path parts representing partial URLs on which
23-
* we'll want to render OpenAPI documentation for the `targetFile`.
23+
* we'll want to render OpenAPI documentation for the `sourceFile`.
2424
*
2525
* Note: path parts will differ based on whether a `versionId` is provided,
2626
* and will differ if there is only a single "service".
@@ -34,7 +34,7 @@ import type { GithubFile } from 'lib/fetch-github-file'
3434
* - ['<versionId>', '<serviceId>'] - when there are multiple services
3535
*/
3636
async function fetchApiDocsPaths({
37-
targetFile,
37+
sourceFile,
3838
versionId,
3939
mayHaveCircularReferences,
4040
}: {
@@ -45,7 +45,7 @@ async function fetchApiDocsPaths({
4545
* - Provide a `string` file path, relative to the current working directory
4646
* from which the website is run, to load a local file.
4747
*/
48-
targetFile: GithubFile | string
48+
sourceFile: GithubFile | string
4949
versionId?: string
5050
/**
5151
* The Waypoint API docs have circular references.
@@ -61,17 +61,17 @@ async function fetchApiDocsPaths({
6161
/**
6262
* Grab the schema.
6363
*
64-
* If the provided `targetFile` is a string, we'll load from the filesystem.
64+
* If the provided `sourceFile` is a string, we'll load from the filesystem.
6565
* Else, we assume a remote GitHub file, and load using the GitHub API.
6666
*
6767
* TODO: would be ideal to validate & properly type the schema, eg with `zod`.
6868
* For now, we cast it to the good-enough ApiDocsSwaggerSchema.
6969
*/
7070
let schema
71-
if (typeof targetFile === 'string') {
72-
schema = await processSchemaFile(targetFile)
71+
if (typeof sourceFile === 'string') {
72+
schema = await processSchemaFile(sourceFile)
7373
} else {
74-
const swaggerFile = await fetchGithubFile(targetFile)
74+
const swaggerFile = await fetchGithubFile(sourceFile)
7575
schema = await processSchemaString(swaggerFile)
7676
}
7777

src/views/api-docs-view/server/get-api-docs-static-paths/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { findLatestStableVersion } from 'lib/api-docs'
1010
import { fetchApiDocsPaths } from './fetch-api-docs-paths'
1111
// Types
1212
import type { GetStaticPathsResult } from 'next'
13-
import type { ApiDocsVersionData, ApiDocsParams } from '../../types'
13+
import type { ApiDocsVersionData } from 'lib/api-docs/types'
14+
import type { ApiDocsParams } from '../../types'
1415
import type { ProductSlug } from 'types/products'
1516

1617
/**
@@ -71,7 +72,7 @@ export async function getApiDocsStaticPaths({
7172
}
7273
// Parse the path parts for all API docs pages we need to statically render.
7374
const apiDocsPaths = await fetchApiDocsPaths({
74-
targetFile: latestStableVersion.targetFile,
75+
sourceFile: latestStableVersion.sourceFile,
7576
mayHaveCircularReferences,
7677
})
7778

src/views/api-docs-view/server/get-api-docs-static-props/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ import {
1616
} from './utils'
1717
// Types
1818
import type { GetStaticPropsResult } from 'next'
19-
import type {
20-
ApiDocsServiceData,
21-
ApiDocsVersionData,
22-
ApiDocsViewProps,
23-
} from '../../types'
19+
import type { ApiDocsVersionData } from 'lib/api-docs/types'
20+
import type { ApiDocsServiceData, ApiDocsViewProps } from '../../types'
2421
import type { ProductData, ProductSlug } from 'types/products'
2522
import type { BreadcrumbLink } from 'components/breadcrumb-bar'
2623
import { cachedGetProductData } from 'lib/get-product-data'
@@ -115,7 +112,7 @@ export async function getApiDocsStaticProps({
115112
* using the current version's Swagger file.
116113
*/
117114
const schemaProps = await buildSchemaProps({
118-
targetFile: currentVersion.targetFile,
115+
sourceFile: currentVersion.sourceFile,
119116
serviceId,
120117
mayHaveCircularReferences,
121118
})

src/views/api-docs-view/server/get-api-docs-static-props/utils/build-schema-props.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type { OperationObjectType } from 'components/open-api-page/types'
2323
import type { ApiDocsSwaggerSchema, ApiDocsServiceData } from '../../../types'
2424

2525
/**
26-
* Given a targetFile, and optional target `serviceId`,
26+
* Given a sourceFile, and optional target `serviceId`,
2727
* fetch the target swagger `.json` file, parse schema information, and
2828
* Return the `schema`, `serviceData` for the target `serviceId`,
2929
* `operationObjects`, and a list of all `serviceId`s.
@@ -35,11 +35,11 @@ import type { ApiDocsSwaggerSchema, ApiDocsServiceData } from '../../../types'
3535
* returns `{ notFound: true }`, which signals that a 404 page should be shown.
3636
*/
3737
async function buildSchemaProps({
38-
targetFile,
38+
sourceFile,
3939
serviceId,
4040
mayHaveCircularReferences,
4141
}: {
42-
targetFile: GithubFile
42+
sourceFile: GithubFile
4343
serviceId?: string
4444
/**
4545
* The Waypoint API docs have circular references.
@@ -63,17 +63,17 @@ async function buildSchemaProps({
6363
/**
6464
* Grab the schema.
6565
*
66-
* If the provided `targetFile` is a string, we'll load from the filesystem.
66+
* If the provided `sourceFile` is a string, we'll load from the filesystem.
6767
* Else, we assume a remote GitHub file, and load using the GitHub API.
6868
*
6969
* TODO: would be ideal to validate & properly type the schema, eg with `zod`.
7070
* For now, we cast it to the good-enough ApiDocsSwaggerSchema.
7171
*/
7272
let schema
73-
if (typeof targetFile === 'string') {
74-
schema = await processSchemaFile(targetFile)
73+
if (typeof sourceFile === 'string') {
74+
schema = await processSchemaFile(sourceFile)
7575
} else {
76-
const swaggerFile = await fetchGithubFile(targetFile)
76+
const swaggerFile = await fetchGithubFile(sourceFile)
7777
schema = await processSchemaString(swaggerFile)
7878
}
7979

0 commit comments

Comments
 (0)