@cparra/apexdocs 3.24.1 → 3.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var errorCollector = require('../error-collector-C2U2sWQ6.js');
4
+ var errorCollector = require('../error-collector-BbdZNqzo.js');
5
5
  var cosmiconfig = require('cosmiconfig');
6
6
  var yargs = require('yargs');
7
7
  var E = require('fp-ts/Either');
@@ -4692,6 +4692,11 @@ class MethodMirrorWrapper {
4692
4692
  var _a;
4693
4693
  return (_a = this.methodMirror.docComment) == null ? void 0 : _a.annotations.find((annotation) => annotation.name.toLowerCase() === annotationName);
4694
4694
  };
4695
+ /** The body of these annotations is expected to be in YAML format. */
4696
+ this.getDocCommentAnnotationsAs = (annotationName) => {
4697
+ var _a, _b;
4698
+ return ((_b = (_a = this.methodMirror.docComment) == null ? void 0 : _a.annotations) != null ? _b : []).filter((annotation) => annotation.name.toLowerCase() === annotationName).map((annotation) => yaml__namespace.load(annotation.bodyLines.join("\n"))).filter((parsed) => parsed !== void 0);
4699
+ };
4695
4700
  }
4696
4701
  }
4697
4702
 
@@ -4907,16 +4912,16 @@ class OpenApiDocsProcessor {
4907
4912
  }
4908
4913
  onProcess(type) {
4909
4914
  var _a, _b;
4910
- const endpointPath = this.getEndpointPath(type);
4911
- if (!endpointPath) {
4915
+ const typeAsClass = type;
4916
+ const endpoint = this.getEndpoint(typeAsClass);
4917
+ if (!endpoint) {
4912
4918
  return;
4913
4919
  }
4920
+ const { path: endpointPath, tagName } = endpoint;
4914
4921
  this.openApiModel.paths[endpointPath] = {};
4915
4922
  if ((_a = type.docComment) == null ? void 0 : _a.description) {
4916
4923
  this.openApiModel.paths[endpointPath].description = type.docComment.description;
4917
4924
  }
4918
- const typeAsClass = type;
4919
- const tagName = camel2title(endpointPath);
4920
4925
  this.openApiModel.tags.push({
4921
4926
  name: tagName,
4922
4927
  description: (_b = type.docComment) == null ? void 0 : _b.description
@@ -4928,7 +4933,7 @@ class OpenApiDocsProcessor {
4928
4933
  parser.parseMethod(typeAsClass, endpointPath, "put", tagName);
4929
4934
  parser.parseMethod(typeAsClass, endpointPath, "delete", tagName);
4930
4935
  }
4931
- getEndpointPath(type) {
4936
+ getEndpoint(type) {
4932
4937
  var _a;
4933
4938
  const restResourceAnnotation = type.annotations.find((element) => element.name.toLowerCase() === "restresource");
4934
4939
  const urlMapping = (_a = restResourceAnnotation == null ? void 0 : restResourceAnnotation.elementValues) == null ? void 0 : _a.find(
@@ -4938,7 +4943,28 @@ class OpenApiDocsProcessor {
4938
4943
  this.logger.error(`Type does not contain urlMapping annotation ${type.name}`);
4939
4944
  return null;
4940
4945
  }
4941
- return urlMapping.value.replaceAll('"', "").replaceAll("'", "").replaceAll("/*", "/");
4946
+ const rawPath = urlMapping.value.replaceAll('"', "").replaceAll("'", "");
4947
+ const segments = rawPath.split("/");
4948
+ const parameterNames = segments.includes("*") ? this.getPathParameterNames(type) : [];
4949
+ let wildcardIndex = 0;
4950
+ let fallbackIndex = 0;
4951
+ const path = segments.map(
4952
+ (segment) => {
4953
+ var _a2;
4954
+ return segment === "*" ? `{${(_a2 = parameterNames[wildcardIndex++]) != null ? _a2 : `param${++fallbackIndex}`}}` : segment;
4955
+ }
4956
+ ).join("/");
4957
+ return { path, tagName: camel2title(segments.filter((segment) => segment !== "*").join("/")) };
4958
+ }
4959
+ /**
4960
+ * Returns the names of all parameters declared as `in: path` through @http-parameter
4961
+ * doc annotations on the class's methods, in the order the methods are declared.
4962
+ */
4963
+ getPathParameterNames(type) {
4964
+ const names = type.methods.flatMap(
4965
+ (method) => new MethodMirrorWrapper(method).getDocCommentAnnotationsAs("http-parameter")
4966
+ ).filter((parameter) => parameter.in === "path" && parameter.name).map((parameter) => parameter.name);
4967
+ return [...new Set(names)];
4942
4968
  }
4943
4969
  }
4944
4970
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var errorCollector = require('./error-collector-C2U2sWQ6.js');
4
+ var errorCollector = require('./error-collector-BbdZNqzo.js');
5
5
  var E = require('fp-ts/Either');
6
6
  require('fp-ts/function');
7
7
  require('fp-ts/TaskEither');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.24.1",
3
+ "version": "3.24.2",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "engines": {
6
6
  "node": ">=22.12.0"