Skip to content
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: add operations tag to esr xml and operationId to yaml #6013

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { nls } from '../messages';
import {
ApexClassOASEligibleResponse,
ApexClassOASGatherContextResponse,
ApexOASInfo
ApexOASInfo,
ExternalServiceOperation
} from '../openApiUtilities/schemas';
import { getTelemetryService } from '../telemetry/telemetry';
import { MetadataOrchestrator } from './metadataOrchestrator';
Expand Down Expand Up @@ -244,6 +245,7 @@ export class ApexActionController {
const baseName = path.basename(fullPath).split('.')[0];
const safeOasSpec = oasSpec.replaceAll('"', ''').replaceAll('type: Id', 'type: string');
const { description, version } = this.extractInfoProperties(safeOasSpec);
const operations = this.getOperationsFromYaml(safeOasSpec);
const orgVersion = await (await WorkspaceContextUtil.getInstance().getConnection()).retrieveMaxApiVersion();
if (!orgVersion) {
throw new Error(nls.localize('error_retrieving_org_version'));
Expand Down Expand Up @@ -274,6 +276,9 @@ export class ApexActionController {
schemaUploadFileName: `${baseName.toLowerCase()}_openapi`,
status: 'Complete',
systemVersion: '3',
operations: {
ExternalServiceOperation: operations
},
registrationProvider: baseName,
...(this.isVersionGte(orgVersion, '63.0') // Guarded inclusion for API version 254 and above (instance api version 63.0 and above)
? {
Expand Down Expand Up @@ -309,9 +314,26 @@ export class ApexActionController {
if (!parsed?.info?.description || !parsed?.info?.version) {
throw new Error(nls.localize('error_parsing_yaml'));
}

return {
description: parsed?.info?.description,
version: parsed?.info?.version
};
};
private getOperationsFromYaml = (oasSpec: string): ExternalServiceOperation[] => {
const parsed = parse(oasSpec);
if (!parsed?.paths) {
throw new Error(nls.localize('error_parsing_yaml'));
}
const operations = parsed.paths
? Object.keys(parsed.paths).flatMap(p =>
Object.keys(parsed.paths[p]).map(operation => ({
name: parsed.paths[p][operation].operationId,
active: true
}))
)
: [];

return operations;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class MetadataOrchestrator {
Ensure no sensitive details are included. Decline requests unrelated to OpenAPI v3 specs or asking for sensitive information.`;

const userPrompt =
'Generate an OpenAPI v3 specification for the following Apex class. The OpenAPI v3 specification should be a YAML file. The paths should be in the format of /{ClassName}/{MethodName} for all the @AuraEnabled methods specified. For every `type: object`, generate a `#/components/schemas` entry for that object. The method should have a $ref entry pointing to the generated `#/components/schemas` entry. Only include methods that have the @AuraEnabled annotation in the paths of the OpenAPI v3 specification. I do not want AUTHOR_PLACEHOLDER in the result. Do not forget info.description property';
'Generate an OpenAPI v3 specification for the following Apex class. The OpenAPI v3 specification should be a YAML file. The paths should be in the format of /{ClassName}/{MethodName} for all the @AuraEnabled methods specified. For every `type: object`, generate a `#/components/schemas` entry for that object. The method should have a $ref entry pointing to the generated `#/components/schemas` entry. Only include methods that have the @AuraEnabled annotation in the paths of the OpenAPI v3 specification. I do not want AUTHOR_PLACEHOLDER in the result. Do not forget info.description property. For each path, you define operations (HTTP methods) that can be used to access that path. Make sure that each operation includes a mandatory operationId property, which should be a unique string matching the operations name.';

const systemTag = '<|system|>';
const endOfPromptTag = '<|endofprompt|>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export type ApexOASInfo = {
description: string;
version: string;
};

export type ExternalServiceOperation = {
name: string;
active: boolean;
};
// export interface ApexClassOASFilter {
// modifiers: string[] | null;
// }
Expand Down
Loading