swaggular 1.0.4 → 1.0.6

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.
@@ -210,23 +210,6 @@ function buildMethodName(method, path, groupedPath, usedNames, serviceName) {
210
210
  nameParts.push('ById');
211
211
  }
212
212
  }
213
- const normalizedPath = path.toLowerCase();
214
- const suffixes = [
215
- { pattern: '/all', label: 'All' },
216
- { pattern: '/search', label: 'Search' },
217
- { pattern: '/stats', label: 'Stats' },
218
- { pattern: '/history', label: 'History' },
219
- { pattern: '/summary', label: 'Summary' },
220
- { pattern: '/details', label: 'Details' },
221
- ];
222
- for (const suffix of suffixes) {
223
- if (normalizedPath.endsWith(suffix.pattern)) {
224
- if (!nameParts.join('').endsWith(suffix.label)) {
225
- nameParts.push(suffix.label);
226
- }
227
- break;
228
- }
229
- }
230
213
  let candidateName = (0, string_utils_1.lowerFirst)(nameParts.join(''));
231
214
  if (candidateName === 'getById' && !usedNames.includes('get')) {
232
215
  candidateName = 'get';
@@ -1,2 +1,7 @@
1
- export declare function buildTypes(masterSchema: any, defaultType?: string): string;
2
- export declare function switchTypeJson(schema: any): string;
1
+ import { OpenAPIV3 } from 'openapi-types';
2
+ /**
3
+ * Converts a JSON schema object to a TypeScript type string.
4
+ * @param schema The JSON schema object or reference object.
5
+ * @returns The corresponding TypeScript type.
6
+ */
7
+ export declare function switchTypeJson(schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | undefined): string;
@@ -1,44 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildTypes = buildTypes;
4
3
  exports.switchTypeJson = switchTypeJson;
5
4
  const interface_state_1 = require("../core/state/interface-state");
6
- function buildTypes(masterSchema, defaultType = 'any') {
7
- if (!masterSchema)
8
- return defaultType;
9
- const jsonSchema = masterSchema?.['content']?.['application/json'];
10
- if (!jsonSchema) {
11
- const formData = masterSchema?.['content']?.['multipart/form-data'];
12
- if (formData) {
13
- return 'FormData';
14
- }
15
- return defaultType;
16
- }
17
- const schema = jsonSchema?.['schema'];
18
- if (!schema || Object.keys(schema).length === 0)
19
- return defaultType;
20
- const ref = schema?.['$ref'];
21
- if (ref) {
22
- const name = ref.split('/').pop();
23
- return interface_state_1.interfaceState.getTypeMapping(name) || name;
24
- }
25
- return switchTypeJson(schema);
26
- }
5
+ const type_guard_1 = require("./type-guard");
6
+ /**
7
+ * Converts a JSON schema object to a TypeScript type string.
8
+ * @param schema The JSON schema object or reference object.
9
+ * @returns The corresponding TypeScript type.
10
+ */
27
11
  function switchTypeJson(schema) {
28
12
  if (!schema || Object.keys(schema).length === 0)
29
13
  return 'any';
30
- const ref = schema?.['$ref'];
31
- const type = schema?.['type'];
32
- const format = schema?.['format'];
33
- if (ref) {
34
- const name = ref.split('/').pop();
14
+ if ((0, type_guard_1.isReference)(schema)) {
15
+ const name = schema.$ref.split('/').pop();
35
16
  return interface_state_1.interfaceState.getTypeMapping(name) || name;
36
17
  }
18
+ const type = schema.type;
19
+ const format = schema.format;
37
20
  if (type === 'object') {
38
21
  return 'any';
39
22
  }
40
23
  if (type === 'array') {
41
- return switchTypeJson(schema?.['items']) + '[]';
24
+ return switchTypeJson(schema.items) + '[]';
42
25
  }
43
26
  if (type === 'number') {
44
27
  return 'number';
@@ -1,4 +1,3 @@
1
- export declare function kebabToCamelCase(str: string): string;
2
1
  export declare function kebabToPascalCase(str: string): string;
3
2
  export declare function removeAllWhitespace(text: string): string;
4
3
  export declare function lowerFirst(str: string): string;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.kebabToCamelCase = kebabToCamelCase;
4
3
  exports.kebabToPascalCase = kebabToPascalCase;
5
4
  exports.removeAllWhitespace = removeAllWhitespace;
6
5
  exports.lowerFirst = lowerFirst;
@@ -8,9 +7,6 @@ exports.upFirst = upFirst;
8
7
  exports.toKebabCase = toKebabCase;
9
8
  exports.normalizeSegment = normalizeSegment;
10
9
  exports.toPascalCase = toPascalCase;
11
- function kebabToCamelCase(str) {
12
- return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
13
- }
14
10
  function kebabToPascalCase(str) {
15
11
  const camel = str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
16
12
  return camel.charAt(0).toUpperCase() + camel.slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggular",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {