Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOP-3963: Render only latest version of spec at base spec component #901

Merged
merged 4 commits into from
Aug 30, 2023
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
25 changes: 23 additions & 2 deletions modules/oas-page-builder/src/services/pageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface AtlasSpecUrlParams {
apiKeyword: string;
apiVersion?: string;
resourceVersion?: string;
latestResourceVersion?: string;
}

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

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

const versionExtension = `${apiVersion ? `-v${apiVersion.split('.')[0]}` : ''}${
apiVersion && resourceVersion ? `-${resourceVersion}` : ''
apiVersion && resourceVersion
? `-${resourceVersion}`
: apiVersion && latestResourceVersion && !resourceVersion
? `-${latestResourceVersion}`
: ''
}`;

let oasFileURL;
Expand Down Expand Up @@ -169,6 +179,17 @@ async function getOASpec({
resourceVersions.length - 1
];

/* Build the latest Resource Version spec if on a base API Version that has multiple Resource Versions
* Do not build the base API VERSION, since it may have out of order resources*/
const { oasFileURL, successfulGitHash } = await getAtlasSpecUrl({
apiKeyword: source,
apiVersion,
resourceVersion,
latestResourceVersion,
});
spec = oasFileURL;
isSuccessfulBuild = successfulGitHash;

versionOptions = {
active: {
apiVersion,
Expand Down
22 changes: 5 additions & 17 deletions modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('pageBuilder', () => {

await buildOpenAPIPages(testEntries, testOptions);

expect(mockExecute).toBeCalledTimes(testEntries.length * 2);
expect(mockExecute).toBeCalledTimes(4);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that we specify toBeCalledWith for each invocation, I'm fine with hardcoding the number of calls now that the logic isn't as straightforwards.

Open to any other equations that determine that intended number of calls though.

// Local
expect(mockExecute).toBeCalledWith(
`${testOptions.repo}/source${testEntries[0][1].source}`,
Expand All @@ -201,12 +201,6 @@ describe('pageBuilder', () => {
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
);

expect(mockExecute).toBeCalledWith(
`${testOptions.repo}/source${testEntries[0][1].source}`,
`${testOptions.output}/${testEntries[0][0]}/index.html`,
expectedDefaultBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
);
// Url
expect(mockExecute).toBeCalledWith(
`${testEntries[1][1].source}`,
Expand All @@ -215,12 +209,6 @@ describe('pageBuilder', () => {
getExpectedVersionOptions(`${SITE_URL}/${testEntries[1][0]}`)
);

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

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION),
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`)
);
Expand Down Expand Up @@ -280,8 +268,8 @@ describe('pageBuilder', () => {
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION),
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION)
);
Expand Down
Loading