-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[W-17756721] fix: add annotation params to prompts (#6063)
* fix: add annotation params to prompts @W-17756721@ add annotation params from context to prompts add process step to resolve semantically duplicate paths * Update packages/salesforcedx-utils-vscode/src/helpers/utils.ts Co-authored-by: Mingxuan Zhang <[email protected]> * chore: apply review suggestions modified annotation prompt builder to exclude Parameters text when no params --------- Co-authored-by: mingxuanzhang <[email protected]> Co-authored-by: Mingxuan Zhang <[email protected]> Co-authored-by: Daphne Yang <[email protected]>
- Loading branch information
1 parent
0817e16
commit 43cac02
Showing
13 changed files
with
239 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
39 changes: 0 additions & 39 deletions
39
...lesforcedx-vscode-apex/src/oas/documentProcessorPipeline/missingPropertiesInjectorStep.ts
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
...ages/salesforcedx-vscode-apex/src/oas/documentProcessorPipeline/propertyCorrectionStep.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,28 @@ | ||
/* | ||
* 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 { ProcessorInputOutput, ProcessorStep } from './processorStep'; | ||
|
||
export class PropertyCorrectionStep implements ProcessorStep { | ||
process(input: ProcessorInputOutput): Promise<ProcessorInputOutput> { | ||
let fixedYaml = this.ensureServersIsPresent(input.yaml); | ||
fixedYaml = this.ensureInfoVersionIsPresent(fixedYaml); | ||
|
||
return new Promise(resolve => { | ||
resolve({ ...input, yaml: fixedYaml }); | ||
}); | ||
} | ||
|
||
private ensureInfoVersionIsPresent(yaml: OpenAPIV3.Document<{}>): OpenAPIV3.Document<{}> { | ||
return { ...yaml, ...{ info: { ...yaml.info, ...{ version: '1.0.0' } } } }; | ||
} | ||
|
||
private ensureServersIsPresent(yaml: OpenAPIV3.Document<{}>): OpenAPIV3.Document<{}> { | ||
return { ...yaml, ...{ servers: [{ url: '/servers/apexrest' }] } }; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...cedx-vscode-apex/src/oas/documentProcessorPipeline/reconcileDuplicateSemanticPathsStep.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,84 @@ | ||
/* | ||
* 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 { JSONPath } from 'jsonpath-plus'; | ||
import { OpenAPIV3 } from 'openapi-types'; | ||
import { ProcessorInputOutput, ProcessorStep } from './processorStep'; | ||
|
||
export class ReconcileDuplicateSemanticPathsStep implements ProcessorStep { | ||
process(input: ProcessorInputOutput): Promise<ProcessorInputOutput> { | ||
const fixedYaml = this.resolvePathsThatAreSemanticallyEqual(input.yaml); | ||
|
||
return new Promise(resolve => { | ||
resolve({ ...input, yaml: fixedYaml }); | ||
}); | ||
} | ||
|
||
private resolvePathsThatAreSemanticallyEqual(yaml: OpenAPIV3.Document): OpenAPIV3.Document { | ||
const newPaths: Record<string, OpenAPIV3.PathItemObject> = {}; | ||
const paramNames: Record<string, string> = {}; | ||
|
||
const pathsToFix = this.getPathsToFix(yaml); | ||
|
||
JSONPath({ | ||
path: '$.paths', | ||
json: yaml, | ||
resultType: 'all', | ||
callback: ({ value }: { value: Record<string, OpenAPIV3.PathItemObject> }) => { | ||
Object.entries(value).forEach(([methodPath, methodValues]) => { | ||
const fromName = this.getNameFromPath(methodPath); | ||
const toName = this.getNameFromPath(pathsToFix[methodPath] ?? methodPath); | ||
const paramName = toName ?? fromName ?? 'param'; | ||
const newPath = pathsToFix[methodPath] ?? methodPath; | ||
|
||
newPaths[newPath] = { ...(newPaths[newPath] ?? {}), ...methodValues }; | ||
|
||
// Store the parameter name for the new path | ||
if (!paramNames[newPath]) { | ||
paramNames[newPath] = paramName; | ||
} | ||
|
||
// Update parameter names to match the new path | ||
JSONPath({ | ||
path: "$..parameters[?(@.in=='path')]", | ||
json: methodValues, | ||
resultType: 'all', | ||
callback: ({ value: paramValue }: { value: OpenAPIV3.ParameterObject }) => { | ||
paramValue.name = paramName; | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
yaml.paths = newPaths; | ||
return yaml; | ||
} | ||
|
||
private getPathsToFix(yaml: OpenAPIV3.Document): Record<string, string> { | ||
const paths = JSONPath({ | ||
path: '$.paths', | ||
json: yaml, | ||
resultType: 'value' | ||
})[0] as Record<string, OpenAPIV3.PathItemObject>; | ||
|
||
return Object.keys(paths) | ||
.filter(path => path.match(/\{[^}]+}/)) | ||
.reduce( | ||
(acc, path, index, thePaths) => { | ||
const toPath = thePaths[0]; | ||
acc[path] = toPath; | ||
return acc; | ||
}, | ||
{} as Record<string, string> | ||
); | ||
} | ||
|
||
private getNameFromPath(path: string): string | undefined { | ||
const match = path.match(/\{([^}]+)}/); | ||
return match ? match[1] : undefined; | ||
} | ||
} |
Oops, something went wrong.