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

Commit 2243f27

Browse files
authored
DOP-3484: Suppress incompatible types warnings for Atlas Admin API (#754)
1 parent 7b6d9d4 commit 2243f27

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ARG SNOOTY_PARSER_VERSION=0.13.16
2525
ARG SNOOTY_FRONTEND_VERSION=0.13.36
2626
# The Redoc CLI branch will most likely stay static. Updates to the branch should
2727
# be limited to CLI bug fixes and Redoc dependency version bumps
28-
ARG REDOC_CLI_VERSION=0.1.1
28+
ARG REDOC_CLI_VERSION=0.2.0
2929
ARG NPM_BASE_64_AUTH
3030
ARG NPM_EMAIL
3131
ENV DEBIAN_FRONTEND=noninteractive

modules/oas-page-builder/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
},
1717
rules: {
1818
'@typescript-eslint/ban-ts-comment': 'off',
19+
'@typescript-eslint/no-explicit-any': 'off',
1920
'no-console': 'off',
2021
},
2122
};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
22
import { normalizePath } from '../utils/normalizePath';
33
import { RedocExecutor } from './redocExecutor';
44
import { findLastSavedGitHash } from './database';
5-
import { OASPageMetadata, PageBuilderOptions } from './types';
5+
import { OASPageMetadata, PageBuilderOptions, RedocBuildOptions } from './types';
66

77
const OAS_FILE_SERVER = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/';
88

@@ -61,6 +61,7 @@ export const buildOpenAPIPages = async (
6161

6262
try {
6363
let spec = '';
64+
const buildOptions: RedocBuildOptions = {};
6465

6566
if (sourceType === 'url') {
6667
spec = source;
@@ -69,12 +70,14 @@ export const buildOpenAPIPages = async (
6970
spec = localFilePath;
7071
} else if (sourceType === 'atlas') {
7172
spec = await getAtlasSpecUrl(source);
73+
// Ignore "incompatible types" warnings for Atlas Admin API/cloud-docs
74+
buildOptions['ignoreIncompatibleTypes'] = true;
7275
} else {
7376
throw new Error(`Unsupported source type "${sourceType}" for ${pageSlug}`);
7477
}
7578

7679
const finalFilename = normalizePath(`${output}/${pageSlug}/index.html`);
77-
await redocExecutor.execute(spec, finalFilename);
80+
await redocExecutor.execute(spec, finalFilename, buildOptions);
7881
} catch (e) {
7982
console.error(e);
8083
// Continue to try to build other pages since it's possible that mut will
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import { exec } from 'child_process';
22
import { promisify } from 'util';
3+
import { RedocBuildOptions } from './types';
34

45
const execCommand = promisify(exec);
56

67
export class RedocExecutor {
78
redocPath: string;
8-
// Stringified options object for Redoc command. Redoc also accepts individual options or a JSON file
9-
private _optionsString: string;
9+
// Options to be passed to Redoc build command
10+
private options: Record<string, any>;
1011

1112
constructor(redocPath: string, siteUrl: string, siteTitle: string) {
1213
this.redocPath = redocPath;
1314

1415
// Custom options DOP defines in the Redoc fork
15-
const customOptions = {
16+
this.options = {
1617
backNavigationPath: siteUrl,
1718
siteTitle,
1819
};
19-
20-
// May contain both native Redoc options and custom DOP options in the future
21-
this._optionsString = JSON.stringify({ customOptions });
2220
}
2321

2422
// Calls Redoc CLI to build spec at given output path
25-
async execute(specSource: string, outputPath: string) {
23+
async execute(specSource: string, outputPath: string, buildOptions: RedocBuildOptions = {}) {
2624
const outputArg = `--output ${outputPath}`;
27-
const optionsArg = `--options '${this._optionsString}'`;
25+
const optionsArg = `--options '${this.finalizeOptions(buildOptions)}'`;
2826
const command = `node ${this.redocPath} build ${specSource} ${outputArg} ${optionsArg}`;
2927

3028
const { stdout, stderr } = await execCommand(command);
@@ -35,4 +33,14 @@ export class RedocExecutor {
3533
throw stderr;
3634
}
3735
}
36+
37+
// Adds any additional options required for current page
38+
private finalizeOptions(buildOptions: RedocBuildOptions = {}): string {
39+
const options = {
40+
...this.options,
41+
...buildOptions,
42+
};
43+
// Stringify JSON object to avoid syntax error when passing object
44+
return JSON.stringify(options);
45+
}
3846
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ export interface BuildMetadata {
1515
export interface PageBuilderOptions extends Omit<ModuleOptions, 'bundle'> {
1616
siteTitle: string;
1717
}
18+
19+
export type RedocBuildOptions = Record<string, any>;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ describe('pageBuilder', () => {
4141
siteUrl: 'https://mongodb.com/docs',
4242
siteTitle: 'Test Docs',
4343
};
44+
const expectedAtlasBuildOptions = {
45+
ignoreIncompatibleTypes: true,
46+
};
47+
const expectedDefaultBuildOptions = {};
4448

4549
beforeEach(() => {
4650
// Reset mock to reset call count
@@ -69,17 +73,20 @@ describe('pageBuilder', () => {
6973
// Local
7074
expect(mockExecute).toBeCalledWith(
7175
`${testOptions.repo}/source${testEntries[0][1].source}`,
72-
`${testOptions.output}/${testEntries[0][0]}/index.html`
76+
`${testOptions.output}/${testEntries[0][0]}/index.html`,
77+
expectedDefaultBuildOptions
7378
);
7479
// Url
7580
expect(mockExecute).toBeCalledWith(
7681
`${testEntries[1][1].source}`,
77-
getExpectedOutputPath(testOptions.output, testEntries[1][0])
82+
getExpectedOutputPath(testOptions.output, testEntries[1][0]),
83+
expectedDefaultBuildOptions
7884
);
7985
// Atlas
8086
expect(mockExecute).toBeCalledWith(
8187
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}.json`,
82-
getExpectedOutputPath(testOptions.output, testEntries[2][0])
88+
getExpectedOutputPath(testOptions.output, testEntries[2][0]),
89+
expectedAtlasBuildOptions
8390
);
8491
});
8592

@@ -93,7 +100,8 @@ describe('pageBuilder', () => {
93100
await buildOpenAPIPages(testEntries, testOptions);
94101
expect(mockExecute).toBeCalledWith(
95102
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${LAST_SAVED_GIT_HASH}.json`,
96-
getExpectedOutputPath(testOptions.output, testEntries[0][0])
103+
getExpectedOutputPath(testOptions.output, testEntries[0][0]),
104+
expectedAtlasBuildOptions
97105
);
98106
});
99107

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,38 @@ cp.exec.mockImplementation((command: string, callback: (a: null, b: string) => v
88
});
99

1010
describe('RedocExecutor', () => {
11+
const testRedocPath = '/path/to/redoc/cli/index.js';
12+
const testSiteUrl = 'https://mongodb.com/docs';
13+
const testSiteTitle = 'Test Docs';
14+
const testSpecSource = '/path/to/spec.json';
15+
const testOutputPath = '/path/to/output/index.html';
16+
1117
it('calls the Redoc build command with expected parameters', async () => {
12-
const testRedocPath = '/path/to/redoc/cli/index.js';
13-
const testSiteUrl = 'https://mongodb.com/docs';
14-
const testSiteTitle = 'Test Docs';
1518
const redocExecutor = new RedocExecutor(testRedocPath, testSiteUrl, testSiteTitle);
16-
17-
const testSpecSource = '/path/to/spec.json';
18-
const testOutputPath = '/path/to/output/index.html';
1919
await redocExecutor.execute(testSpecSource, testOutputPath);
2020

2121
const expectedOptions = {
22-
customOptions: {
23-
backNavigationPath: testSiteUrl,
24-
siteTitle: testSiteTitle,
25-
},
22+
backNavigationPath: testSiteUrl,
23+
siteTitle: testSiteTitle,
24+
};
25+
const expectedCommand = `node ${testRedocPath} build ${testSpecSource} --output ${testOutputPath} --options '${JSON.stringify(
26+
expectedOptions
27+
)}'`;
28+
expect(cp.exec).toBeCalledWith(expectedCommand, expect.anything());
29+
});
30+
31+
it('accepts additional build options', async () => {
32+
const redocExecutor = new RedocExecutor(testRedocPath, testSiteUrl, testSiteTitle);
33+
const testBuildOptions = {
34+
ignoreIncompatibleTypes: true,
35+
};
36+
await redocExecutor.execute(testSpecSource, testOutputPath, testBuildOptions);
37+
38+
// Options should be concatenated together
39+
const expectedOptions = {
40+
backNavigationPath: testSiteUrl,
41+
siteTitle: testSiteTitle,
42+
ignoreIncompatibleTypes: true,
2643
};
2744
const expectedCommand = `node ${testRedocPath} build ${testSpecSource} --output ${testOutputPath} --options '${JSON.stringify(
2845
expectedOptions

0 commit comments

Comments
 (0)