-
Notifications
You must be signed in to change notification settings - Fork 408
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
[W-17756721] fix: add annotation params to prompts #6063
base: feat/apex-oas
Are you sure you want to change the base?
Changes from all commits
0ce0b3a
bbb919b
4d7da46
cbe2fa5
0a8592e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
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' }] } }; | ||
} | ||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this step to capture what placeholders are on the path and make sure those placeholders have their corresponding parameters in path? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If so, I think we also need to do vice versa, make sure those parameters in: path show up in the request path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mingxuanzhangsfdx please log a ticket for the case to make sure those parameters in: path show up in the request path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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; | ||
} | ||
} |
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.
a bit worried if this can be fully bundled. Will give a try
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.
I saw a note on the npm page regarding bundling. It mentioned that bundling for nodejs should be good, but thank you for the "trust but verify" commitment.