diff --git a/CHANGELOG.md b/CHANGELOG.md index be27e02..ebefa34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Snippets: `devproxy-plugin-rewrite-file` - RewritePlugin rewrites file - Snippets: `devproxy-plugin-rewrite-file-schema` - RewritePlugin rewrites file schema - Diagnostics: Show warning if config contains a summary plugin without a reporter +- Diagnostics: Show warning if OpenApiSpecGeneratorPlugin is placed after ApiCenterOnboardingPlugin ### Changed: diff --git a/README.md b/README.md index 71226e9..3b7d174 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ The following sections describe the features that the extension contributes to V - Check that a plugin can be configured with a configSection - Check for configSections that are not used in plugins - Check for reporter plugin when a summary plugin is used +- Check that ApiCenterOnboardingPlugin is placed after OpenApiSpecGeneratorPlugin ### Editor Actions diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 472c15f..ee0f000 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -107,6 +107,7 @@ const checkPlugins = (pluginsNode: parse.PropertyNode | undefined, diagnostics: warnOnReporterPosition(pluginNodes, diagnostics); validatePluginConfigurations(pluginNodes, diagnostics, documentNode); checkForSummaryPluginWithoutReporter(pluginNodes, diagnostics); + checkAPICOnboardingPluginAfterOpenApiSpecGeneratorPlugin(pluginNodes, diagnostics); } }; @@ -341,4 +342,47 @@ function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], d ); } } +} + +function checkAPICOnboardingPluginAfterOpenApiSpecGeneratorPlugin(pluginNodes: parse.ObjectNode[], diagnostics: vscode.Diagnostic[]) { + const openApiSpecGeneratorPluginIndex = pluginNodes.findIndex((pluginNode: parse.ObjectNode) => { + const pluginNameNode = getASTNode( + pluginNode.children, + 'Identifier', + 'name' + ); + const pluginName = (pluginNameNode?.value as parse.LiteralNode) + .value as string; + const enabledNode = getASTNode( + pluginNode.children, + 'Identifier', + 'enabled' + ); + const isEnabled = (enabledNode?.value as parse.LiteralNode) + .value as boolean; + return pluginName === 'OpenApiSpecGeneratorPlugin' && isEnabled; + } + ); + if (openApiSpecGeneratorPluginIndex !== -1) { + const apiCenterOnboardingPluginIndex = pluginNodes.findIndex((pluginNode: parse.ObjectNode) => { + const pluginNameNode = getASTNode( + pluginNode.children, + 'Identifier', + 'name' + ); + const pluginName = (pluginNameNode?.value as parse.LiteralNode) + .value as string; + return pluginName === 'ApiCenterOnboardingPlugin'; + } + ); + if (apiCenterOnboardingPluginIndex !== -1 && apiCenterOnboardingPluginIndex < openApiSpecGeneratorPluginIndex) { + diagnostics.push( + new vscode.Diagnostic( + getRangeFromASTNode(pluginNodes[openApiSpecGeneratorPluginIndex]), + 'OpenApiSpecGeneratorPlugin should be placed before ApiCenterOnboardingPlugin.', + vscode.DiagnosticSeverity.Warning + ) + ); + } + } } \ No newline at end of file