Skip to content

Commit b100e30

Browse files
chore: encoded in MD, chars in SD
1 parent 5f64455 commit b100e30

File tree

6 files changed

+140
-20
lines changed

6 files changed

+140
-20
lines changed

src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ export type ESR = JsonMap & {
2121
};
2222

2323
export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer {
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-
});
35-
3624
// eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars
3725
public async toSourceFormat(input: {
3826
component: SourceComponent;
@@ -76,9 +64,16 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
7664
component.type.directoryName,
7765
`${esrFileName}-meta.xml`
7866
);
67+
const xmlBuilder = new XMLBuilder({
68+
format: true,
69+
ignoreAttributes: false,
70+
suppressUnpairedNode: true,
71+
processEntities: false,
72+
indentBy: ' ',
73+
});
7974
writeInfos.push({
8075
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
81-
source: this.xmlBuilder.build({ ExternalServiceRegistration: esrContent }),
76+
source: xmlBuilder.build({ ExternalServiceRegistration: esrContent }),
8277
output: esrFilePath,
8378
});
8479

@@ -93,25 +88,34 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
9388
const writeInfos: WriteInfo[] = [];
9489
const esrFilePath = this.getOutputFile(component);
9590
const esrContent = await fs.readFile(esrFilePath, 'utf8');
91+
const xmlParser = new XMLParser({
92+
ignoreAttributes: false,
93+
});
9694
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
97-
const esrXml = this.xmlParser.parse(esrContent);
95+
const esrXml = xmlParser.parse(esrContent);
9896

9997
// Read schema content from file
10098
const schemaFileName = `${component.fullName}.yaml`; // or .json based on your logic
10199
const schemaFilePath = path.join(path.dirname(esrFilePath) ?? '', schemaFileName);
102-
const schemaContent = await fs.readFile(schemaFilePath, 'utf8');
103-
104100
// Add schema content back to ESR content
105101
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
106-
esrXml.ExternalServiceRegistration['schema'] = schemaContent;
102+
esrXml.ExternalServiceRegistration['schema'] = await fs.readFile(schemaFilePath, 'utf8');
107103
const esrMdApiFilePath = `${path.join(
108104
this.defaultDirectory ?? '',
109105
component.type.directoryName,
110106
component.fullName
111107
)}.externalServiceRegistration`;
112108

109+
const xmlBuilder = new XMLBuilder({
110+
format: true,
111+
ignoreAttributes: false,
112+
suppressUnpairedNode: true,
113+
processEntities: true,
114+
indentBy: ' ',
115+
});
116+
113117
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
114-
const source = this.xmlBuilder.build(esrXml);
118+
const source = xmlBuilder.build(esrXml);
115119

116120
// Write combined content back to source format
117121
writeInfos.push({

test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-md-files.expected/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<registrationProviderType>Custom</registrationProviderType>
55
<schemaType>OpenApi3</schemaType>
66
<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>
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>
88
<status>Complete</status>
99
<systemVersion>3</systemVersion>
1010
<schema>openapi: 3.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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>{"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}}</serviceBinding>
8+
<status>Complete</status>
9+
<systemVersion>3</systemVersion>
10+
</ExternalServiceRegistration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
openapi: 3.0.0
2+
info:
3+
title: OpenAPIChallenge
4+
description: Now is the time for Apex OpenAPI
5+
version: 63.1.0
6+
paths:
7+
/getAccountSummaryWithOpportunities:
8+
operations:
9+
get:
10+
summary: need to figure out what this means
11+
description: need to figure out what this means
12+
operationId: getAccountSummaryWithOpportunities
13+
responses: {}
14+
/getActiveCases:
15+
operations:
16+
get:
17+
summary: need to figure out what this means
18+
description: need to figure out what this means
19+
operationId: getActiveCases
20+
responses: {}
21+
/getAllAccounts:
22+
operations:
23+
get:
24+
summary: need to figure out what this means
25+
description: need to figure out what this means
26+
operationId: getAllAccounts
27+
responses: {}
28+
/getUserDetails:
29+
operations:
30+
get:
31+
summary: need to figure out what this means
32+
description: need to figure out what this means
33+
operationId: getUserDetails
34+
responses: {}
35+
/updateContactDetails:
36+
operations:
37+
get:
38+
summary: need to figure out what this means
39+
description: need to figure out what this means
40+
operationId: updateContactDetails
41+
responses: {}
42+
/getWelcomeMessage:
43+
operations:
44+
get:
45+
summary: need to figure out what this means
46+
description: need to figure out what this means
47+
operationId: getWelcomeMessage
48+
responses: {}

test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<registrationProviderType>Custom</registrationProviderType>
55
<schemaType>OpenApi3</schemaType>
66
<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>
7+
<serviceBinding>{"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}}</serviceBinding>
88
<status>Complete</status>
99
<systemVersion>3</systemVersion>
1010
</ExternalServiceRegistration>
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>{&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+
<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>

0 commit comments

Comments
 (0)