Skip to content

Commit 8d9515f

Browse files
committed
Add diagnostics for ApiCenterOnboardingPlugin placement relative to OpenApiSpecGeneratorPlugin. Closes #93
Closes #93
1 parent 12f3162 commit 8d9515f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Snippets: `devproxy-plugin-rewrite-file` - RewritePlugin rewrites file
1616
- Snippets: `devproxy-plugin-rewrite-file-schema` - RewritePlugin rewrites file schema
1717
- Diagnostics: Show warning if config contains a summary plugin without a reporter
18+
- Diagnostics: Show warning if OpenApiSpecGeneratorPlugin is placed after ApiCenterOnboardingPlugin
1819

1920
### Changed:
2021

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following sections describe the features that the extension contributes to V
3939
- Check that a plugin can be configured with a configSection
4040
- Check for configSections that are not used in plugins
4141
- Check for reporter plugin when a summary plugin is used
42+
- Check that ApiCenterOnboardingPlugin is placed after OpenApiSpecGeneratorPlugin
4243

4344
### Editor Actions
4445

src/diagnostics.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const checkPlugins = (pluginsNode: parse.PropertyNode | undefined, diagnostics:
107107
warnOnReporterPosition(pluginNodes, diagnostics);
108108
validatePluginConfigurations(pluginNodes, diagnostics, documentNode);
109109
checkForSummaryPluginWithoutReporter(pluginNodes, diagnostics);
110+
checkAPICOnboardingPluginAfterOpenApiSpecGeneratorPlugin(pluginNodes, diagnostics);
110111
}
111112
};
112113

@@ -341,4 +342,47 @@ function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], d
341342
);
342343
}
343344
}
345+
}
346+
347+
function checkAPICOnboardingPluginAfterOpenApiSpecGeneratorPlugin(pluginNodes: parse.ObjectNode[], diagnostics: vscode.Diagnostic[]) {
348+
const openApiSpecGeneratorPluginIndex = pluginNodes.findIndex((pluginNode: parse.ObjectNode) => {
349+
const pluginNameNode = getASTNode(
350+
pluginNode.children,
351+
'Identifier',
352+
'name'
353+
);
354+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
355+
.value as string;
356+
const enabledNode = getASTNode(
357+
pluginNode.children,
358+
'Identifier',
359+
'enabled'
360+
);
361+
const isEnabled = (enabledNode?.value as parse.LiteralNode)
362+
.value as boolean;
363+
return pluginName === 'OpenApiSpecGeneratorPlugin' && isEnabled;
364+
}
365+
);
366+
if (openApiSpecGeneratorPluginIndex !== -1) {
367+
const apiCenterOnboardingPluginIndex = pluginNodes.findIndex((pluginNode: parse.ObjectNode) => {
368+
const pluginNameNode = getASTNode(
369+
pluginNode.children,
370+
'Identifier',
371+
'name'
372+
);
373+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
374+
.value as string;
375+
return pluginName === 'ApiCenterOnboardingPlugin';
376+
}
377+
);
378+
if (apiCenterOnboardingPluginIndex !== -1 && apiCenterOnboardingPluginIndex < openApiSpecGeneratorPluginIndex) {
379+
diagnostics.push(
380+
new vscode.Diagnostic(
381+
getRangeFromASTNode(pluginNodes[openApiSpecGeneratorPluginIndex]),
382+
'OpenApiSpecGeneratorPlugin should be placed before ApiCenterOnboardingPlugin.',
383+
vscode.DiagnosticSeverity.Warning
384+
)
385+
);
386+
}
387+
}
344388
}

0 commit comments

Comments
 (0)