Skip to content

Commit 1ff64ea

Browse files
committed
Move 'preprocessOpenApiSpecs' call to docusaurus config
1 parent 8155836 commit 1ff64ea

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

docusaurus.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import type { Config } from "@docusaurus/types";
99
import type * as Preset from "@docusaurus/preset-classic";
1010
import matter from "gray-matter";
1111
import listRemote from "./docusaurus-lib-list-remote";
12-
import { openApiSpecs } from "./preprocessing";
12+
import { preprocessOpenApiSpecs, openApiSpecs } from './src/openapi/preprocessing';
1313
import languageTabs from "./openapi-generated-clients";
1414
import { getSpecDocumentationPlugins } from './src/utils/spec-documentation';
1515

16+
// Execute the preprocessing function for OpenAPI specs
17+
preprocessOpenApiSpecs().catch(error => {
18+
console.error('Failed to preprocess OpenAPI specs:', error);
19+
process.exit(1);
20+
});
21+
1622
const otdfctl = listRemote.createRepo("opentdf", "otdfctl", "main");
1723

1824
const config: Config = {

src/openapi/preprocessing.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
3+
When making changes to this file, consider: https://virtru.atlassian.net/browse/DSPX-1577
4+
5+
*/
16
import * as fs from 'fs';
27
import * as path from 'path';
38
import * as yaml from 'js-yaml';
@@ -22,7 +27,7 @@ const specsProcessedDir = path.join(repoRoot, 'specs-processed');
2227
const ADD_TIMESTAMP_TO_DESCRIPTION = false;
2328

2429
// The location prefix of built OpenAPI documentation
25-
const OUTPUT_PREFIX = 'docs/OpenAPI-clients';
30+
const OUTPUT_PREFIX = path.join(repoRoot, 'docs', 'OpenAPI-clients');
2631

2732
// The index page for OpenAPI documentation, to support bookmarking & sharing the URL
2833
const OPENAPI_INDEX_PAGE = `${OUTPUT_PREFIX}/index.md`;
@@ -158,21 +163,21 @@ async function copySamplesToProcessedSpecs() {
158163

159164
console.log('🔄 Ensuring sample files exist in "specs-processed" directory...');
160165

161-
const processedDir = path.resolve(__dirname, 'specs-processed');
162-
fs.mkdirSync(processedDir, { recursive: true });
163-
166+
// Use canonical processed and source directories
167+
fs.mkdirSync(specsProcessedDir, { recursive: true });
168+
164169
// Handle petstore specifically - it has a downloadUrl
165-
const petstorePath = path.resolve(__dirname, 'specs-processed/petstore.yaml');
166-
const petstoreSourcePath = path.resolve(__dirname, 'specs/petstore.yaml');
167-
170+
const petstorePath = path.join(specsProcessedDir, 'petstore.yaml');
171+
const petstoreSourcePath = path.join(specsDir, 'petstore.yaml');
172+
168173
// Always copy from source directory, overwriting if it exists
169174
console.log(`Copying petstore spec from ${petstoreSourcePath}`);
170175
fs.copyFileSync(petstoreSourcePath, petstorePath);
171-
176+
172177
// Handle bookstore specifically
173-
const bookstorePath = path.resolve(__dirname, 'specs-processed/bookstore.yaml');
174-
const bookstoreSourcePath = path.resolve(__dirname, 'specs/bookstore.yaml');
175-
178+
const bookstorePath = path.join(specsProcessedDir, 'bookstore.yaml');
179+
const bookstoreSourcePath = path.join(specsDir, 'bookstore.yaml');
180+
176181
// Always copy from source directory, overwriting if it exists
177182
console.log(`Copying bookstore spec from ${bookstoreSourcePath}`);
178183
fs.copyFileSync(bookstoreSourcePath, bookstorePath);
@@ -206,14 +211,14 @@ async function preprocessOpenApiSpecs() {
206211

207212
// Generate modified path if not specified
208213
if (!spec.specPathModified) {
209-
// Store processed files in a 'specs-processed' directory by default
210-
spec.specPathModified = path.join(
211-
parsedPath.dir.replace(/^\.\/specs/, './specs-processed'),
212-
parsedPath.base
213-
);
214+
// Extract the relative path from specsDir
215+
const relativePath = path.relative(specsDir, spec.specPath);
216+
217+
// Store processed files in 'specs-processed' directory while preserving the original directory structure
218+
spec.specPathModified = path.join(specsProcessedDir, relativePath);
214219
}
215220

216-
const targetPath = path.resolve(__dirname, spec.specPathModified);
221+
const targetPath = path.resolve(spec.specPathModified);
217222

218223
console.log(`Processing: ${sourcePath}${targetPath}`);
219224

@@ -313,10 +318,6 @@ Expand each section in the navigation panel to access the OpenAPI documentation
313318
console.log('✨ OpenAPI preprocessing complete');
314319
};
315320

316-
// Execute the preprocessing function
317-
preprocessOpenApiSpecs().catch(error => {
318-
console.error('Failed to preprocess OpenAPI specs:', error);
319-
process.exit(1);
320-
});
321321

322-
export { openApiSpecs, openApiSpecsArray };
322+
// Export the function and data without automatically executing it
323+
export { openApiSpecs, openApiSpecsArray, preprocessOpenApiSpecs };

0 commit comments

Comments
 (0)