Skip to content

Commit 1cb9d00

Browse files
authored
Openapi leading slash (#195)
1 parent 8b405e9 commit 1cb9d00

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

examples/open-api/docs/openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"paths": {
13-
"AccountService/": {
13+
"/AccountService/": {
1414
"description": "Account related operations",
1515
"get": {
1616
"tags": [
@@ -338,7 +338,7 @@
338338
}
339339
}
340340
},
341-
"Contact/": {
341+
"/Contact/": {
342342
"description": "Contact related operations",
343343
"get": {
344344
"tags": [
@@ -359,7 +359,7 @@
359359
}
360360
}
361361
},
362-
"Order/": {
362+
"/Order/": {
363363
"description": "Order related operations",
364364
"get": {
365365
"tags": [

examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithInnerClass.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @description Contact related operations
33
*/
4-
@RestResource(urlMapping='/Contact/*')
4+
@RestResource(UrlMapping='/Contact/*')
55
global with sharing class SampleRestResourceWithInnerClass {
66
/**
77
* @description This is a sample HTTP Get method

examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithoutApexDocs.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @description Order related operations
33
*/
4-
@RestResource(urlMapping='/Order/*')
4+
@RestResource(UrlMapping='/Order/*')
55
global with sharing class SampleRestResourceWithoutApexDocs {
66
@HttpGet
77
global static String doGet(String param1, Reference1 param2) {

src/core/openapi/__tests__/open-api-docs-processor.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ it('should add a path based on the @UrlResource annotation on the class', functi
2424
const processor = new OpenApiDocsProcessor(noLogger);
2525
processor.onProcess(classMirror);
2626

27-
expect(processor.openApiModel.paths).toHaveProperty('Account/');
27+
expect(processor.openApiModel.paths).toHaveProperty('/Account/');
2828
});
2929

3030
it('should respect slashes', function () {
3131
const annotationElementValue = {
3232
key: 'urlMapping',
33-
value: "'v1/Account/*'",
33+
value: "'/v1/Account/*'",
3434
};
3535
const classMirror = new ClassMirrorBuilder()
3636
.addAnnotation(new AnnotationBuilder().addElementValue(annotationElementValue).build())
@@ -39,7 +39,7 @@ it('should respect slashes', function () {
3939
const processor = new OpenApiDocsProcessor(noLogger);
4040
processor.onProcess(classMirror);
4141

42-
expect(processor.openApiModel.paths).toHaveProperty('v1/Account/');
42+
expect(processor.openApiModel.paths).toHaveProperty('/v1/Account/');
4343
});
4444

4545
it('should contain a path with a description when the class has an ApexDoc comment', function () {
@@ -55,5 +55,5 @@ it('should contain a path with a description when the class has an ApexDoc comme
5555
const processor = new OpenApiDocsProcessor(noLogger);
5656
processor.onProcess(classMirror);
5757

58-
expect(processor.openApiModel.paths['Account/'].description).toBe('My Description');
58+
expect(processor.openApiModel.paths['/Account/'].description).toBe('My Description');
5959
});

src/core/openapi/open-api-docs-processor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ export class OpenApiDocsProcessor {
8484
return null;
8585
}
8686

87-
let endpointPath = urlMapping.value.replaceAll('"', '').replaceAll("'", '').replaceAll('/*', '/');
88-
if (endpointPath.startsWith('/')) {
89-
endpointPath = endpointPath.substring(1);
90-
}
91-
return endpointPath;
87+
// The OpenApi path needs to start with a leading slash, but
88+
// Salesforce @RestResource annotations already require a leading slash,
89+
// so no need to check for it.
90+
// See URL Guidelines: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_rest_resource.htm
91+
return urlMapping.value.replaceAll('"', '').replaceAll("'", '').replaceAll('/*', '/');
9292
}
9393
}

0 commit comments

Comments
 (0)