beer-swagger 1.0.1 → 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.
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GitToolBoxProjectSettings">
4
+ <option name="commitMessageIssueKeyValidationOverride">
5
+ <BoolValueOverride>
6
+ <option name="enabled" value="true" />
7
+ </BoolValueOverride>
8
+ </option>
9
+ <option name="commitMessageValidationEnabledOverride">
10
+ <BoolValueOverride>
11
+ <option name="enabled" value="true" />
12
+ </BoolValueOverride>
13
+ </option>
14
+ </component>
15
+ </project>
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();
@@ -197,6 +208,13 @@ function mapSchemaToType(schema, schemas, useTypes) {
197
208
  }
198
209
  return useTypes ? `Types.${refName}` : '{}';
199
210
  }
211
+ if (!type && items) {
212
+ const itemType = mapSchemaToType(items, schemas, useTypes);
213
+ if (itemType === '{}' || itemType === '[]') {
214
+ return '[]';
215
+ }
216
+ return `${itemType}[]`;
217
+ }
200
218
  if (type === 'string') {
201
219
  return 'string';
202
220
  }
@@ -235,11 +253,15 @@ function mapParamSchemaToType(schema, schemas, useTypes) {
235
253
  type,
236
254
  format
237
255
  } = schema;
256
+ const { items } = schema;
238
257
  if ($ref) {
239
258
  const refName = normalizeDtoName($ref.split('/')
240
259
  .pop());
241
260
  return useTypes ? `Types.${refName}` : '{}';
242
261
  }
262
+ if (!type && items) {
263
+ return '[]';
264
+ }
243
265
  if (type === 'string') {
244
266
  return 'string';
245
267
  }
@@ -422,6 +444,10 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
422
444
  if (name === 'unnamed') {
423
445
  name = toCamel(opId);
424
446
  }
447
+ const pathParams = getParams(op).filter((p) => p.in === 'path');
448
+ if (method === 'delete' && pathParams.length === 1) {
449
+ name = 'removeBy';
450
+ }
425
451
  if (!KEEP_METHOD_NAMES.has(name.toLowerCase()) && isAllLowerWord(name)) {
426
452
  const inferred = pathToName(p);
427
453
  const pathSegments = p.split('/')
@@ -498,7 +524,7 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
498
524
  if (seen.has(name)) {
499
525
  const paramSuffix = toParamSuffix(entryParams, paramNameMap);
500
526
  if (paramSuffix) {
501
- name = `${entryName}${paramSuffix}`;
527
+ name = appendParamSuffix(entryName, paramSuffix);
502
528
  }
503
529
  }
504
530
  if (seen.has(name)) {
@@ -665,7 +691,7 @@ function generateForSpec(spec, serviceName, fileBase, clientType) {
665
691
 
666
692
  const baseName = toServiceBaseName(serviceName);
667
693
  const apiClassName = `${toPascal(baseName)}Api`;
668
- const factoryName = `get${apiClassName}`;
694
+ const factoryName = apiClassName === 'ApiApi' ? 'getApi' : `get${apiClassName}`;
669
695
  const cacheName = `${baseName}ApiCache`;
670
696
  const lines = [];
671
697
  lines.push('/*');
@@ -725,6 +751,10 @@ function mapSchemaToTsType(schema, schemas) {
725
751
  }
726
752
  return normalizeDtoName(refName);
727
753
  }
754
+ if (!type && items) {
755
+ const itemType = mapSchemaToTsType(items, schemas);
756
+ return `${itemType}[]`;
757
+ }
728
758
  if (schemaEnum && schemaEnum.length) {
729
759
  return schemaEnum.map((v) => (typeof v === 'string' ? `'${v}'` : String(v)))
730
760
  .join(' | ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beer-swagger",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "bin": {
5
5
  "beer-swagger": "./generate-apis.js"
6
6
  },
Binary file