-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: method validation step in OAS #6038
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b65ab9a
feat: method validation step
mingxuanzhangsfdx 5598079
feat: display errors in problem tab from method validation
mingxuanzhangsfdx 56e5d5d
Merge branch 'feat/apex-oas' into mz/method-validation-step
mingxuanzhangsfdx 65e5c0e
fix: test
mingxuanzhangsfdx 6a9bdf1
chore: set default formatter in vscode and revert format changes
mingxuanzhangsfdx 1d44174
Update packages/salesforcedx-vscode-apex/src/oas/documentProcessorPip…
mingxuanzhangsfdx 4c8838e
chore: apply suggestions
mingxuanzhangsfdx 4eea9ff
Merge branch 'feat/apex-oas' into mz/method-validation-step
mingxuanzhangsfdx db813a3
chore: fix merging errors
mingxuanzhangsfdx e2e8e75
chore: refactor errors in processor
mingxuanzhangsfdx 84e59ee
Merge branch 'feat/apex-oas' into mz/method-validation-step
mingxuanzhangsfdx ee7e3f6
chore: fix
mingxuanzhangsfdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/salesforcedx-vscode-apex/src/oas/documentProcessorPipeline/methodValidationStep.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2025, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { OpenAPIV3 } from 'openapi-types'; | ||
import * as vscode from 'vscode'; | ||
import { nls } from '../../messages'; | ||
import { ApexClassOASEligibleResponse, OpenAPIDoc } from '../schemas'; | ||
import { ProcessorInputOutput, ProcessorStep } from './processorStep'; | ||
export class MethodValidationStep implements ProcessorStep { | ||
static diagnosticCollection: vscode.DiagnosticCollection = | ||
vscode.languages.createDiagnosticCollection('OAS Method Validations'); | ||
private className: string = ''; | ||
private virtualUri: vscode.Uri | null = null; // the url of the virtual YAML file | ||
private diagnostics: vscode.Diagnostic[] = []; | ||
constructor() {} | ||
process(input: ProcessorInputOutput): Promise<ProcessorInputOutput> { | ||
this.className = input.context.classDetail.name as string; | ||
this.virtualUri = vscode.Uri.parse(`untitled:${this.className}_OAS_temp.yaml`); | ||
MethodValidationStep.diagnosticCollection.clear(); | ||
const cleanedupYaml = this.validateMethods(input.yaml, input.eligibilityResult); | ||
MethodValidationStep.diagnosticCollection.set(this.virtualUri, this.diagnostics); | ||
input.errors = [...input.errors, ...this.diagnostics]; | ||
return new Promise(resolve => { | ||
resolve({ ...input, yaml: cleanedupYaml }); | ||
}); | ||
} | ||
|
||
private validateMethods( | ||
parsed: OpenAPIV3.Document, | ||
eligibilityResult: ApexClassOASEligibleResponse | ||
): OpenAPIV3.Document { | ||
const symbols = eligibilityResult.symbols; | ||
if (!symbols || symbols.length === 0) { | ||
throw new Error(nls.localize('no_eligible_method')); | ||
} | ||
const methodNames = new Set( | ||
symbols.filter(symbol => symbol.isApexOasEligible).map(symbol => symbol.docSymbol.name) | ||
); | ||
|
||
for (const [path, methods] of Object.entries(parsed?.paths || {})) { | ||
const methodName = path.split('/').pop(); | ||
// make sure all eligible methods are present in the document | ||
if (!methodName || !methodNames.has(methodName)) { | ||
this.diagnostics.push( | ||
new vscode.Diagnostic( | ||
new vscode.Range(0, 0, 0, 0), | ||
nls.localize('ineligible_method_in_doc', methodName), | ||
vscode.DiagnosticSeverity.Error | ||
) | ||
); | ||
} else { | ||
methodNames.delete(methodName); | ||
} | ||
} | ||
|
||
if (methodNames.size > 0) { | ||
this.diagnostics.push( | ||
new vscode.Diagnostic( | ||
new vscode.Range(0, 0, 0, 0), | ||
nls.localize('eligible_method_not_in_doc', Array.from(methodNames).join(', ')), | ||
vscode.DiagnosticSeverity.Error | ||
) | ||
); | ||
} | ||
return parsed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mingxuanzhangsfdx Thanks for catching the AuraEnabled message! I believe this message should be more general. Http annotations are the current ones, but I imagine AuraEnabled will eventually return. What do think about referring the user to current documentation regarding what makes an Apex method eligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I just noticed that the sentence is only used when one method is selected for generation. Since it is not required by TDX, I guess we can leave it for now?