beer-swagger 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/generate-apis.js +17 -2
  2. package/package.json +1 -1
package/generate-apis.js CHANGED
@@ -105,6 +105,17 @@ function toParamSuffix(params, nameMap) {
105
105
  .join('');
106
106
  }
107
107
 
108
+ // Avoid duplicate "By" when the base method name already ends with it.
109
+ function appendParamSuffix(baseName, paramSuffix) {
110
+ if (!paramSuffix) {
111
+ return baseName;
112
+ }
113
+ if (baseName.endsWith('By') && paramSuffix.startsWith('By')) {
114
+ return baseName + paramSuffix.slice(2);
115
+ }
116
+ return `${baseName}${paramSuffix}`;
117
+ }
118
+
108
119
  // Add a verb for single-segment paths when needed.
109
120
  function addVerbForSingleSegment(name, method) {
110
121
  const lower = name.toLowerCase();
@@ -433,6 +444,10 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
433
444
  if (name === 'unnamed') {
434
445
  name = toCamel(opId);
435
446
  }
447
+ const pathParams = getParams(op).filter((p) => p.in === 'path');
448
+ if (method === 'delete' && pathParams.length === 1) {
449
+ name = 'removeBy';
450
+ }
436
451
  if (!KEEP_METHOD_NAMES.has(name.toLowerCase()) && isAllLowerWord(name)) {
437
452
  const inferred = pathToName(p);
438
453
  const pathSegments = p.split('/')
@@ -509,7 +524,7 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
509
524
  if (seen.has(name)) {
510
525
  const paramSuffix = toParamSuffix(entryParams, paramNameMap);
511
526
  if (paramSuffix) {
512
- name = `${entryName}${paramSuffix}`;
527
+ name = appendParamSuffix(entryName, paramSuffix);
513
528
  }
514
529
  }
515
530
  if (seen.has(name)) {
@@ -676,7 +691,7 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
676
691
 
677
692
  const baseName = toServiceBaseName(serviceName);
678
693
  const apiClassName = `${toPascal(baseName)}Api`;
679
- const factoryName = `get${apiClassName}`;
694
+ const factoryName = apiClassName === 'ApiApi' ? 'getApi' : `get${apiClassName}`;
680
695
  const cacheName = `${baseName}ApiCache`;
681
696
  const lines = [];
682
697
  lines.push('/*');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beer-swagger",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "bin": {
5
5
  "beer-swagger": "./generate-apis.js"
6
6
  },