Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 7d20361

Browse files
casthewizmmeigs
andauthored
DOP-3963: Render only latest version of spec at base spec component (#901)
* build staging ecs on push * DOP-3963: Update tests & stage * Update .github/workflows/deploy-stg-ecs.yml --------- Co-authored-by: Matt Meigs <[email protected]>
1 parent d21b958 commit 7d20361

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

modules/oas-page-builder/src/services/pageBuilder.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface AtlasSpecUrlParams {
4545
apiKeyword: string;
4646
apiVersion?: string;
4747
resourceVersion?: string;
48+
latestResourceVersion?: string;
4849
}
4950

5051
const ensureSavedVersionDataMatches = (versions: VersionData, apiVersion?: string, resourceVersion?: string) => {
@@ -57,7 +58,12 @@ const ensureSavedVersionDataMatches = (versions: VersionData, apiVersion?: strin
5758
}
5859
};
5960

60-
const getAtlasSpecUrl = async ({ apiKeyword, apiVersion, resourceVersion }: AtlasSpecUrlParams) => {
61+
const getAtlasSpecUrl = async ({
62+
apiKeyword,
63+
apiVersion,
64+
resourceVersion,
65+
latestResourceVersion,
66+
}: AtlasSpecUrlParams) => {
6167
// Currently, the only expected API fetched programmatically is the Cloud Admin API,
6268
// but it's possible to have more in the future with varying processes.
6369
const keywords = ['cloud'];
@@ -66,7 +72,11 @@ const getAtlasSpecUrl = async ({ apiKeyword, apiVersion, resourceVersion }: Atla
6672
}
6773

6874
const versionExtension = `${apiVersion ? `-v${apiVersion.split('.')[0]}` : ''}${
69-
apiVersion && resourceVersion ? `-${resourceVersion}` : ''
75+
apiVersion && resourceVersion
76+
? `-${resourceVersion}`
77+
: apiVersion && latestResourceVersion && !resourceVersion
78+
? `-${latestResourceVersion}`
79+
: ''
7080
}`;
7181

7282
let oasFileURL;
@@ -169,6 +179,17 @@ async function getOASpec({
169179
resourceVersions.length - 1
170180
];
171181

182+
/* Build the latest Resource Version spec if on a base API Version that has multiple Resource Versions
183+
* Do not build the base API VERSION, since it may have out of order resources*/
184+
const { oasFileURL, successfulGitHash } = await getAtlasSpecUrl({
185+
apiKeyword: source,
186+
apiVersion,
187+
resourceVersion,
188+
latestResourceVersion,
189+
});
190+
spec = oasFileURL;
191+
isSuccessfulBuild = successfulGitHash;
192+
172193
versionOptions = {
173194
active: {
174195
apiVersion,

modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('pageBuilder', () => {
192192

193193
await buildOpenAPIPages(testEntries, testOptions);
194194

195-
expect(mockExecute).toBeCalledTimes(testEntries.length * 2);
195+
expect(mockExecute).toBeCalledTimes(4);
196196
// Local
197197
expect(mockExecute).toBeCalledWith(
198198
`${testOptions.repo}/source${testEntries[0][1].source}`,
@@ -201,12 +201,6 @@ describe('pageBuilder', () => {
201201
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
202202
);
203203

204-
expect(mockExecute).toBeCalledWith(
205-
`${testOptions.repo}/source${testEntries[0][1].source}`,
206-
`${testOptions.output}/${testEntries[0][0]}/index.html`,
207-
expectedDefaultBuildOptions,
208-
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
209-
);
210204
// Url
211205
expect(mockExecute).toBeCalledWith(
212206
`${testEntries[1][1].source}`,
@@ -215,12 +209,6 @@ describe('pageBuilder', () => {
215209
getExpectedVersionOptions(`${SITE_URL}/${testEntries[1][0]}`)
216210
);
217211

218-
expect(mockExecute).toBeCalledWith(
219-
`${testEntries[1][1].source}`,
220-
getExpectedOutputPath(testOptions.output, testEntries[1][0], API_VERSION),
221-
expectedDefaultBuildOptions,
222-
getExpectedVersionOptions(`${SITE_URL}/${testEntries[1][0]}`)
223-
);
224212
// Atlas
225213
expect(mockExecute).toBeCalledWith(
226214
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
@@ -230,8 +218,8 @@ describe('pageBuilder', () => {
230218
);
231219

232220
expect(mockExecute).toBeCalledWith(
233-
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
234-
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION),
221+
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
222+
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION),
235223
expectedAtlasBuildOptions,
236224
getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`)
237225
);
@@ -280,8 +268,8 @@ describe('pageBuilder', () => {
280268
);
281269

282270
expect(mockExecute).toBeCalledWith(
283-
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
284-
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION),
271+
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
272+
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION),
285273
expectedAtlasBuildOptions,
286274
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION)
287275
);

0 commit comments

Comments
 (0)