diff --git a/examples/open-api/docs/openapi.json b/examples/open-api/docs/openapi.json index 43c4b59f..f2e60a56 100644 --- a/examples/open-api/docs/openapi.json +++ b/examples/open-api/docs/openapi.json @@ -10,7 +10,7 @@ } ], "paths": { - "AccountService/": { + "/AccountService/": { "description": "Account related operations", "get": { "tags": [ @@ -338,7 +338,7 @@ } } }, - "Contact/": { + "/Contact/": { "description": "Contact related operations", "get": { "tags": [ @@ -359,7 +359,7 @@ } } }, - "Order/": { + "/Order/": { "description": "Order related operations", "get": { "tags": [ diff --git a/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithInnerClass.cls b/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithInnerClass.cls index f1847a67..c3a46488 100644 --- a/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithInnerClass.cls +++ b/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithInnerClass.cls @@ -1,7 +1,7 @@ /** * @description Contact related operations */ -@RestResource(urlMapping='/Contact/*') +@RestResource(UrlMapping='/Contact/*') global with sharing class SampleRestResourceWithInnerClass { /** * @description This is a sample HTTP Get method diff --git a/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithoutApexDocs.cls b/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithoutApexDocs.cls index c0981306..0742b893 100644 --- a/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithoutApexDocs.cls +++ b/examples/open-api/force-app/main/default/classes/rest/SampleRestResourceWithoutApexDocs.cls @@ -1,7 +1,7 @@ /** * @description Order related operations */ -@RestResource(urlMapping='/Order/*') +@RestResource(UrlMapping='/Order/*') global with sharing class SampleRestResourceWithoutApexDocs { @HttpGet global static String doGet(String param1, Reference1 param2) { diff --git a/package.json b/package.json index 2b7631ed..10c9bc27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cparra/apexdocs", - "version": "3.3.1", + "version": "3.3.2", "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.", "keywords": [ "apex", diff --git a/src/core/openapi/__tests__/open-api-docs-processor.spec.ts b/src/core/openapi/__tests__/open-api-docs-processor.spec.ts index 45817899..bdbbeb1b 100644 --- a/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +++ b/src/core/openapi/__tests__/open-api-docs-processor.spec.ts @@ -24,13 +24,13 @@ it('should add a path based on the @UrlResource annotation on the class', functi const processor = new OpenApiDocsProcessor(noLogger); processor.onProcess(classMirror); - expect(processor.openApiModel.paths).toHaveProperty('Account/'); + expect(processor.openApiModel.paths).toHaveProperty('/Account/'); }); it('should respect slashes', function () { const annotationElementValue = { key: 'urlMapping', - value: "'v1/Account/*'", + value: "'/v1/Account/*'", }; const classMirror = new ClassMirrorBuilder() .addAnnotation(new AnnotationBuilder().addElementValue(annotationElementValue).build()) @@ -39,7 +39,7 @@ it('should respect slashes', function () { const processor = new OpenApiDocsProcessor(noLogger); processor.onProcess(classMirror); - expect(processor.openApiModel.paths).toHaveProperty('v1/Account/'); + expect(processor.openApiModel.paths).toHaveProperty('/v1/Account/'); }); 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 const processor = new OpenApiDocsProcessor(noLogger); processor.onProcess(classMirror); - expect(processor.openApiModel.paths['Account/'].description).toBe('My Description'); + expect(processor.openApiModel.paths['/Account/'].description).toBe('My Description'); }); diff --git a/src/core/openapi/open-api-docs-processor.ts b/src/core/openapi/open-api-docs-processor.ts index 5f52ae21..522d3226 100644 --- a/src/core/openapi/open-api-docs-processor.ts +++ b/src/core/openapi/open-api-docs-processor.ts @@ -84,10 +84,10 @@ export class OpenApiDocsProcessor { return null; } - let endpointPath = urlMapping.value.replaceAll('"', '').replaceAll("'", '').replaceAll('/*', '/'); - if (endpointPath.startsWith('/')) { - endpointPath = endpointPath.substring(1); - } - return endpointPath; + // The OpenApi path needs to start with a leading slash, but + // Salesforce @RestResource annotations already require a leading slash, + // so no need to check for it. + // See URL Guidelines: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_rest_resource.htm + return urlMapping.value.replaceAll('"', '').replaceAll("'", '').replaceAll('/*', '/'); } }