Skip to content

Commit 5f64455

Browse files
committed
chore: wip
1 parent 484663a commit 5f64455

File tree

7 files changed

+109
-17
lines changed

7 files changed

+109
-17
lines changed

src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ export type ESR = JsonMap & {
2121
};
2222

2323
export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer {
24-
private xmlParser = new XMLParser({ ignoreAttributes: false });
25-
private xmlBuilder = new XMLBuilder({ ignoreAttributes: false });
24+
private xmlParser = new XMLParser({
25+
ignoreAttributes: false,
26+
processEntities: false, // Disable automatic decoding of entities
27+
});
28+
private xmlBuilder = new XMLBuilder({
29+
format: true,
30+
ignoreAttributes: false,
31+
suppressUnpairedNode: true,
32+
processEntities: true,
33+
indentBy: ' ',
34+
});
2635

2736
// eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars
2837
public async toSourceFormat(input: {
@@ -88,19 +97,27 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
8897
const esrXml = this.xmlParser.parse(esrContent);
8998

9099
// Read schema content from file
91-
const schemaFileName = `${component.fullName}.schema.yaml`; // or .json based on your logic
92-
const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName);
100+
const schemaFileName = `${component.fullName}.yaml`; // or .json based on your logic
101+
const schemaFilePath = path.join(path.dirname(esrFilePath) ?? '', schemaFileName);
93102
const schemaContent = await fs.readFile(schemaFilePath, 'utf8');
94103

95104
// Add schema content back to ESR content
96105
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
97-
esrXml.ExternalServiceRegistration.schema = { _text: schemaContent };
106+
esrXml.ExternalServiceRegistration['schema'] = schemaContent;
107+
const esrMdApiFilePath = `${path.join(
108+
this.defaultDirectory ?? '',
109+
component.type.directoryName,
110+
component.fullName
111+
)}.externalServiceRegistration`;
112+
113+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
114+
const source = this.xmlBuilder.build(esrXml);
98115

99116
// Write combined content back to source format
100117
writeInfos.push({
101118
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
102-
source: this.xmlBuilder.build(esrXml),
103-
output: esrFilePath,
119+
source,
120+
output: path.resolve(esrMdApiFilePath),
104121
});
105122

106123
return writeInfos;

src/registry/presets/decomposeExternalServiceRegistrationBeta.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@
2525
"decomposition": "topLevel",
2626
"transformer": "decomposeExternalServiceRegistration"
2727
},
28-
"strictDirectoryName": true,
2928
"suffix": "externalServiceRegistration",
30-
"supportsPartialDelete": true
29+
"supportsPartialDelete": false
3130
}
3231
},
3332
"suffixes": {
3433
"yaml": "yaml",
3534
"externalServiceRegistration": "externalserviceregistration"
3635
},
37-
"strictDirectoryNames": {
38-
"externalServiceRegistrations": "externalserviceregistration"
39-
},
36+
"strictDirectoryNames": {},
4037
"childTypes": {
4138
"yaml": "externalserviceregistration"
4239
}

test/snapshot/helper/conversions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ export const sourceToMdapi = async (testDir: string): Promise<string[]> => {
9292
};
9393

9494
/** checks that the two xml bodies have the same equivalent json (handles out-of-order things, etc) */
95-
export const compareTwoXml = (file1: string, file2: string): Chai.Assertion =>
96-
expect(parser.parse(file1)).to.deep.equalInAnyOrder(parser.parse(file2));
95+
export const compareTwoXml = (file1: string, file2: string): Chai.Assertion => {
96+
const f1doc = parser.parse(file1);
97+
const f2doc = parser.parse(file2);
98+
return expect(f1doc).to.deep.equalInAnyOrder(f2doc);
99+
};
97100

98101
/**
99102
* catches missing files by asserting that two directories have the exact same children
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
2+
<label>BankService</label>
3+
<namedCredential>ntest</namedCredential>
4+
<registrationProviderType>Custom</registrationProviderType>
5+
<schemaType>OpenApi3</schemaType>
6+
<schemaUrl>/accounts/schema</schemaUrl>
7+
<serviceBinding>{&amp;quot;host&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;basePath&amp;quot;:&amp;quot;/&amp;quot;,&amp;quot;allowedSchemes&amp;quot;:[],&amp;quot;requestMediaTypes&amp;quot;:[],&amp;quot;responseMediaTypes&amp;quot;:[],&amp;quot;compatibleMediaTypes&amp;quot;:{}}</serviceBinding>
8+
<status>Complete</status>
9+
<systemVersion>3</systemVersion>
10+
<schema>openapi: 3.0.0
11+
info:
12+
title: OpenAPIChallenge
13+
description: Now is the time for Apex OpenAPI
14+
version: 63.1.0
15+
paths:
16+
/getAccountSummaryWithOpportunities:
17+
operations:
18+
get:
19+
summary: need to figure out what this means
20+
description: need to figure out what this means
21+
operationId: getAccountSummaryWithOpportunities
22+
responses: {}
23+
/getActiveCases:
24+
operations:
25+
get:
26+
summary: need to figure out what this means
27+
description: need to figure out what this means
28+
operationId: getActiveCases
29+
responses: {}
30+
/getAllAccounts:
31+
operations:
32+
get:
33+
summary: need to figure out what this means
34+
description: need to figure out what this means
35+
operationId: getAllAccounts
36+
responses: {}
37+
/getUserDetails:
38+
operations:
39+
get:
40+
summary: need to figure out what this means
41+
description: need to figure out what this means
42+
operationId: getUserDetails
43+
responses: {}
44+
/updateContactDetails:
45+
operations:
46+
get:
47+
summary: need to figure out what this means
48+
description: need to figure out what this means
49+
operationId: updateContactDetails
50+
responses: {}
51+
/getWelcomeMessage:
52+
operations:
53+
get:
54+
summary: need to figure out what this means
55+
description: need to figure out what this means
56+
operationId: getWelcomeMessage
57+
responses: {}</schema>
58+
</ExternalServiceRegistration>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<types>
4+
<members>OpenAPIChallenge</members>
5+
<name>ExternalServiceRegistration</name>
6+
</types>
7+
<version>60.0</version>
8+
</Package>
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata"><label>BankService</label><namedCredential>ntest</namedCredential><registrationProviderType>Custom</registrationProviderType><schemaType>OpenApi3</schemaType><schemaUrl>/accounts/schema</schemaUrl><serviceBinding>{&quot;host&quot;:&quot;&quot;,&quot;basePath&quot;:&quot;/&quot;,&quot;allowedSchemes&quot;:[],&quot;requestMediaTypes&quot;:[],&quot;responseMediaTypes&quot;:[],&quot;compatibleMediaTypes&quot;:{}}</serviceBinding><status>Complete</status><systemVersion>3</systemVersion></ExternalServiceRegistration>
1+
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
2+
<label>BankService</label>
3+
<namedCredential>ntest</namedCredential>
4+
<registrationProviderType>Custom</registrationProviderType>
5+
<schemaType>OpenApi3</schemaType>
6+
<schemaUrl>/accounts/schema</schemaUrl>
7+
<serviceBinding>{&quot;host&quot;:&quot;&quot;,&quot;basePath&quot;:&quot;/&quot;,&quot;allowedSchemes&quot;:[],&quot;requestMediaTypes&quot;:[],&quot;responseMediaTypes&quot;:[],&quot;compatibleMediaTypes&quot;:{}}</serviceBinding>
8+
<status>Complete</status>
9+
<systemVersion>3</systemVersion>
10+
</ExternalServiceRegistration>

test/snapshot/sampleProjects/preset-decomposedESR/snapshots.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ describe('fully decomposed external service registration via decomposeExternalSe
4141
await fileSnap(file, testDir);
4242
}
4343
await dirsAreIdentical(
44-
path.join(testDir, 'force-app'),
45-
path.join(testDir, '__snapshots__', 'verify-md-files.expected', 'force-app')
44+
path.join(testDir, 'mdapiOutput'),
45+
path.join(testDir, '__snapshots__', 'verify-md-files.expected')
4646
);
4747
});
4848
it('round trip of metadata format is equivalent', async () => {

0 commit comments

Comments
 (0)