Skip to content

Commit

Permalink
Ensure docPath corresponds to docsPluginId when pluginId is passed (#277
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sserrata authored Sep 21, 2022
1 parent add3e20 commit c6fef0a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/docusaurus-plugin-openapi-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,20 @@ export default function pluginOpenAPIDocs(
const presets: any = siteConfig.presets;
const plugins: any = siteConfig.plugins;
const presetsPlugins = presets.concat(plugins);
const docData: any = getDocsPluginConfig(presetsPlugins, docsPluginId);
const docRouteBasePath = docData ? docData.routeBasePath : undefined;
const docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
let docData: any = getDocsPluginConfig(presetsPlugins, docsPluginId);
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;

async function generateApiDocs(options: APIOptions) {
async function generateApiDocs(options: APIOptions, pluginId: any) {
let { specPath, outputDir, template, sidebarOptions } = options;

// Override docPath if pluginId provided
if (pluginId) {
docData = getDocsPluginConfig(presetsPlugins, pluginId);
docRouteBasePath = docData ? docData.routeBasePath : undefined;
docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
}

const contentPath = isURL(specPath)
? specPath
: path.resolve(siteDir, specPath);
Expand Down Expand Up @@ -414,10 +421,12 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
const pluginId = options.pluginId;
const pluginInstances = getPluginInstances(plugins);
let targetConfig: any;
let targetDocsPluginId: any;
if (pluginId) {
try {
const pluginConfig = getPluginConfig(plugins, pluginId);
targetConfig = pluginConfig.config ?? {};
targetDocsPluginId = pluginConfig.docsPluginId;
} catch {
console.error(
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
Expand Down Expand Up @@ -445,15 +454,15 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
);
} else {
Object.keys(targetConfig).forEach(async function (key) {
await generateApiDocs(targetConfig[key]);
await generateApiDocs(targetConfig[key], targetDocsPluginId);
});
}
} else if (!targetConfig[id]) {
console.error(
chalk.red(`ID '${id}' does not exist in OpenAPI docs config.`)
);
} else {
await generateApiDocs(targetConfig[id]);
await generateApiDocs(targetConfig[id], targetDocsPluginId);
}
});

Expand All @@ -470,10 +479,12 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
const pluginId = options.pluginId;
const pluginInstances = getPluginInstances(plugins);
let targetConfig: any;
let targetDocsPluginId: any;
if (pluginId) {
try {
const pluginConfig = getPluginConfig(plugins, pluginId);
targetConfig = pluginConfig.config ?? {};
targetDocsPluginId = pluginConfig.docsPluginId;
} catch {
console.error(
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
Expand Down Expand Up @@ -526,7 +537,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
...parentConfig,
...versionConfig,
};
await generateApiDocs(mergedConfig);
await generateApiDocs(mergedConfig, targetDocsPluginId);
});
}
} else if (!versions[versionId]) {
Expand All @@ -542,7 +553,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
...versionConfig,
};
await generateVersions(mergedVersions, parentConfig.outputDir);
await generateApiDocs(mergedConfig);
await generateApiDocs(mergedConfig, targetDocsPluginId);
}
});

Expand Down

0 comments on commit c6fef0a

Please sign in to comment.