swaggular 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/dist/app/get-parse-args.js +48 -0
- package/dist/app/parse-variables.js +24 -0
- package/dist/builders/build-comments.js +25 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.js +48 -0
- package/dist/cli/variables.d.ts +2 -0
- package/dist/cli/variables.js +23 -0
- package/dist/core/state/interface-state.d.ts +17 -0
- package/dist/core/state/interface-state.js +21 -0
- package/dist/core/state/service-state.d.ts +9 -0
- package/dist/core/state/service-state.js +18 -0
- package/dist/core/state/swagger-state.d.ts +14 -0
- package/dist/core/state/swagger-state.js +36 -0
- package/dist/examples/services/get.example.js +1 -0
- package/dist/generators/generate-comments.js +40 -0
- package/dist/generators/generate-interface.js +219 -0
- package/dist/generators/generate-service.js +302 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +45 -0
- package/dist/models/file-content.js +2 -0
- package/dist/models/grouped-paths.js +2 -0
- package/dist/models/interface-data.js +2 -0
- package/dist/models/parsed-args.js +2 -0
- package/dist/models/service-data.js +2 -0
- package/dist/models/types.js +29 -0
- package/dist/parsers/path-grouper.d.ts +17 -0
- package/dist/parsers/path-grouper.js +207 -0
- package/dist/parsers/swagger-parser.d.ts +4 -0
- package/dist/parsers/swagger-parser.js +53 -0
- package/dist/renderers/generate-comments.d.ts +3 -0
- package/dist/renderers/generate-comments.js +40 -0
- package/dist/renderers/generate-interface.d.ts +12 -0
- package/dist/renderers/generate-interface.js +209 -0
- package/dist/renderers/generate-service.d.ts +9 -0
- package/dist/renderers/generate-service.js +178 -0
- package/dist/stores/interface-data-store.js +62 -0
- package/dist/stores/services-store.js +18 -0
- package/dist/stores/swagger-store.js +324 -0
- package/dist/templates/angular-template.js +23 -0
- package/dist/templates/paged-request-template.js +22 -0
- package/dist/templates/paged-result-template.js +13 -0
- package/dist/templates/services/angular-template.d.ts +15 -0
- package/dist/templates/services/angular-template.js +24 -0
- package/dist/templates/services/http-params-handler.d.ts +2 -0
- package/dist/templates/services/http-params-handler.js +12 -0
- package/dist/templates/types/extends-from-types.d.ts +3 -0
- package/dist/templates/types/extends-from-types.js +72 -0
- package/dist/templates/types/generic-types.d.ts +4 -0
- package/dist/templates/types/generic-types.js +72 -0
- package/dist/translators/add-import-to-interface.js +21 -0
- package/dist/translators/generate-interfaces.js +134 -0
- package/dist/translators/generate-services.js +192 -0
- package/dist/translators/join-with-templates.js +16 -0
- package/dist/translators/splitPaths.js +8 -0
- package/dist/types/file-content.d.ts +6 -0
- package/dist/types/file-content.js +2 -0
- package/dist/types/grouped-paths.d.ts +7 -0
- package/dist/types/grouped-paths.js +2 -0
- package/dist/types/interface-data.d.ts +13 -0
- package/dist/types/interface-data.js +2 -0
- package/dist/types/parsed-args.d.ts +9 -0
- package/dist/types/parsed-args.js +2 -0
- package/dist/types/service-data.d.ts +21 -0
- package/dist/types/service-data.js +2 -0
- package/dist/types/types.d.ts +23 -0
- package/dist/types/types.js +29 -0
- package/dist/utils/build-types.d.ts +2 -0
- package/dist/utils/build-types.js +66 -0
- package/dist/utils/create-file.d.ts +7 -0
- package/dist/utils/create-file.js +74 -0
- package/dist/utils/generate-imports.js +33 -0
- package/dist/utils/grouping-paths.js +68 -0
- package/dist/utils/method-builders.js +77 -0
- package/dist/utils/object-utils.d.ts +1 -0
- package/dist/utils/object-utils.js +11 -0
- package/dist/utils/path-utils.d.ts +7 -0
- package/dist/utils/path-utils.js +61 -0
- package/dist/utils/string-utils.d.ts +13 -0
- package/dist/utils/string-utils.js +47 -0
- package/dist/utils/to-case.js +47 -0
- package/dist/utils/type-guard.d.ts +5 -0
- package/dist/utils/type-guard.js +35 -0
- package/package.json +64 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.primitivesTypes = void 0;
|
|
4
|
+
exports.getImports = getImports;
|
|
5
|
+
exports.primitivesTypes = [
|
|
6
|
+
"string",
|
|
7
|
+
"number",
|
|
8
|
+
"boolean",
|
|
9
|
+
"void",
|
|
10
|
+
"any",
|
|
11
|
+
"blob",
|
|
12
|
+
"file",
|
|
13
|
+
];
|
|
14
|
+
function getImports(typeNames) {
|
|
15
|
+
const realImports = new Set();
|
|
16
|
+
for (const typeName of typeNames) {
|
|
17
|
+
const transformedTypeName = typeName
|
|
18
|
+
.replaceAll("[", "")
|
|
19
|
+
.replaceAll("]", "");
|
|
20
|
+
if (exports.primitivesTypes.includes(transformedTypeName.toLowerCase())) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (transformedTypeName.includes("<")) {
|
|
24
|
+
const types = transformedTypeName.replaceAll(">", "").split("<");
|
|
25
|
+
types.forEach((t) => {
|
|
26
|
+
realImports.add(t.trim());
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
realImports.add(transformedTypeName);
|
|
31
|
+
}
|
|
32
|
+
return Array.from(realImports);
|
|
33
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupPaths = groupPaths;
|
|
4
|
+
function isVariable(segment) {
|
|
5
|
+
return /^\{.+\}$/.test(segment);
|
|
6
|
+
}
|
|
7
|
+
function normalizeSegment(segment) {
|
|
8
|
+
return segment
|
|
9
|
+
.split("-")
|
|
10
|
+
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
|
11
|
+
.join("");
|
|
12
|
+
}
|
|
13
|
+
function toPascalCase(segments) {
|
|
14
|
+
return segments.map(normalizeSegment).join("");
|
|
15
|
+
}
|
|
16
|
+
function extractNonVariableSegments(path) {
|
|
17
|
+
return path
|
|
18
|
+
.split("/")
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.filter((s) => s !== "api")
|
|
21
|
+
.filter((s) => !isVariable(s));
|
|
22
|
+
}
|
|
23
|
+
function groupPaths(paths) {
|
|
24
|
+
const temp = {};
|
|
25
|
+
// 1️⃣ recolectar segmentos NO variables (ignorando /api) pero guardar el path original
|
|
26
|
+
for (const originalPath of Object.keys(paths)) {
|
|
27
|
+
if (!originalPath.startsWith("/api/"))
|
|
28
|
+
continue;
|
|
29
|
+
const clean = originalPath.replace(/^\/api\//, "");
|
|
30
|
+
const segments = clean.split("/").filter((s) => s && !isVariable(s));
|
|
31
|
+
if (segments.length === 0)
|
|
32
|
+
continue;
|
|
33
|
+
const root = segments[0];
|
|
34
|
+
if (!temp[root])
|
|
35
|
+
temp[root] = [];
|
|
36
|
+
temp[root].push({
|
|
37
|
+
originalPath,
|
|
38
|
+
segments,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const groups = {};
|
|
42
|
+
// 2️⃣ decidir si colapsa por root o usa deep=2
|
|
43
|
+
for (const [root, entries] of Object.entries(temp)) {
|
|
44
|
+
const hasDeeperStructure = entries.some((e) => e.segments.length >= 3);
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
let baseSegments;
|
|
47
|
+
if (!hasDeeperStructure) {
|
|
48
|
+
// colapsa por root común
|
|
49
|
+
baseSegments = [root];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// deep máximo = 2
|
|
53
|
+
baseSegments = entry.segments.slice(0, 2);
|
|
54
|
+
}
|
|
55
|
+
const groupName = toPascalCase(baseSegments);
|
|
56
|
+
if (!groups[groupName]) {
|
|
57
|
+
groups[groupName] = {
|
|
58
|
+
groupName,
|
|
59
|
+
baseSegments,
|
|
60
|
+
paths: [],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// ✅ path completo, con /api y variables
|
|
64
|
+
groups[groupName].paths.push(entry.originalPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return groups;
|
|
68
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeResponseType = computeResponseType;
|
|
4
|
+
exports.computeRequestBodyType = computeRequestBodyType;
|
|
5
|
+
exports.buildUrl = buildUrl;
|
|
6
|
+
exports.buildGetContent = buildGetContent;
|
|
7
|
+
exports.buildPutContent = buildPutContent;
|
|
8
|
+
exports.buildPostContent = buildPostContent;
|
|
9
|
+
exports.buildDeleteContent = buildDeleteContent;
|
|
10
|
+
exports.buildPatchContent = buildPatchContent;
|
|
11
|
+
const build_types_1 = require("./build-types");
|
|
12
|
+
const to_case_1 = require("./to-case");
|
|
13
|
+
function computeResponseType(successSchema) {
|
|
14
|
+
return (0, build_types_1.buildTypes)(successSchema, "void");
|
|
15
|
+
}
|
|
16
|
+
function computeRequestBodyType(requestBodySchema) {
|
|
17
|
+
const content = requestBodySchema?.content;
|
|
18
|
+
if (!content || Object.keys(content).length === 0)
|
|
19
|
+
return null;
|
|
20
|
+
return (0, build_types_1.buildTypes)(requestBodySchema, "any");
|
|
21
|
+
}
|
|
22
|
+
function buildUrl(path, baseUrl) {
|
|
23
|
+
const leftover = path.replace(baseUrl, "");
|
|
24
|
+
const segments = leftover.split("/").filter(Boolean);
|
|
25
|
+
let finalUrl = `\`\${this.baseUrl}`;
|
|
26
|
+
segments.forEach((s) => {
|
|
27
|
+
if (s.startsWith("{") && s.endsWith("}")) {
|
|
28
|
+
const id = (0, to_case_1.lowerFirst)(s.replace("{", "").replace("}", ""));
|
|
29
|
+
finalUrl += `/\${${id}}`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
finalUrl += `/${s}`;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
finalUrl += `\``;
|
|
36
|
+
return finalUrl;
|
|
37
|
+
}
|
|
38
|
+
function buildGetContent(responseType, path, baseUrl, hasParameters) {
|
|
39
|
+
const finalUrl = buildUrl(path, baseUrl);
|
|
40
|
+
if (hasParameters) {
|
|
41
|
+
return `\t\tconst params = HttpHelper.toHttpParams(parameters ?? {});
|
|
42
|
+
\t\treturn this.http.get<${responseType}>(${finalUrl}, { params });`;
|
|
43
|
+
}
|
|
44
|
+
if (responseType === "Blob") {
|
|
45
|
+
return `\t\treturn this.http.get(${finalUrl}, { responseType: 'blob' });`;
|
|
46
|
+
}
|
|
47
|
+
return `\t\treturn this.http.get<${responseType}>(${finalUrl});`;
|
|
48
|
+
}
|
|
49
|
+
function buildPutContent(responseType, path, baseUrl, hasRequestBody) {
|
|
50
|
+
const finalUrl = buildUrl(path, baseUrl);
|
|
51
|
+
if (!hasRequestBody) {
|
|
52
|
+
return `\t\treturn this.http.put<${responseType}>(${finalUrl});`;
|
|
53
|
+
}
|
|
54
|
+
return `\t\treturn this.http.put<${responseType}>(${finalUrl}, requestBody);`;
|
|
55
|
+
}
|
|
56
|
+
function buildPostContent(responseType, path, baseUrl, hasRequestBody) {
|
|
57
|
+
const finalUrl = buildUrl(path, baseUrl);
|
|
58
|
+
if (!hasRequestBody) {
|
|
59
|
+
return `\t\treturn this.http.post<${responseType}>(${finalUrl});`;
|
|
60
|
+
}
|
|
61
|
+
return `\t\treturn this.http.post<${responseType}>(${finalUrl}, requestBody);`;
|
|
62
|
+
}
|
|
63
|
+
function buildDeleteContent(responseType, path, baseUrl, hasParameters) {
|
|
64
|
+
const finalUrl = buildUrl(path, baseUrl);
|
|
65
|
+
if (hasParameters) {
|
|
66
|
+
return `\t\tconst params = HttpHelper.toHttpParams(parameters ?? {});
|
|
67
|
+
\t\treturn this.http.delete<${responseType}>(${finalUrl}, { params });`;
|
|
68
|
+
}
|
|
69
|
+
return `\t\treturn this.http.delete<${responseType}>(${finalUrl});`;
|
|
70
|
+
}
|
|
71
|
+
function buildPatchContent(responseType, path, baseUrl, hasRequestBody) {
|
|
72
|
+
const finalUrl = buildUrl(path, baseUrl);
|
|
73
|
+
if (!hasRequestBody) {
|
|
74
|
+
return `\t\treturn this.http.patch<${responseType}>(${finalUrl});`;
|
|
75
|
+
}
|
|
76
|
+
return `\t\treturn this.http.patch<${responseType}>(${finalUrl}, requestBody);`;
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeFalsyValues(obj: Record<string, any>): Record<string, any>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeFalsyValues = removeFalsyValues;
|
|
4
|
+
function removeFalsyValues(obj) {
|
|
5
|
+
const newObj = {};
|
|
6
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
7
|
+
if (value)
|
|
8
|
+
newObj[key] = value;
|
|
9
|
+
}
|
|
10
|
+
return newObj;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function isVariable(segment: string): boolean;
|
|
2
|
+
export declare function getExtraSegments(fullPath: string, baseUrl: string): string[];
|
|
3
|
+
export declare function removeVariablesFromPath(path: string): string;
|
|
4
|
+
export declare function createBaseUrl(baseSegments: string[]): string;
|
|
5
|
+
export declare function findCommonBaseUrl(paths: string[]): string;
|
|
6
|
+
export declare function pathWithoutVariables(segments: string[]): string;
|
|
7
|
+
export declare function standarizedPath(path: string): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVariable = isVariable;
|
|
4
|
+
exports.getExtraSegments = getExtraSegments;
|
|
5
|
+
exports.removeVariablesFromPath = removeVariablesFromPath;
|
|
6
|
+
exports.createBaseUrl = createBaseUrl;
|
|
7
|
+
exports.findCommonBaseUrl = findCommonBaseUrl;
|
|
8
|
+
exports.pathWithoutVariables = pathWithoutVariables;
|
|
9
|
+
exports.standarizedPath = standarizedPath;
|
|
10
|
+
function isVariable(segment) {
|
|
11
|
+
return /^\{.+\}$/.test(segment);
|
|
12
|
+
}
|
|
13
|
+
function getExtraSegments(fullPath, baseUrl) {
|
|
14
|
+
if (!fullPath.startsWith('api') && !fullPath.startsWith('/api')) {
|
|
15
|
+
fullPath = '/api/' + fullPath;
|
|
16
|
+
}
|
|
17
|
+
const path = fullPath.replace(baseUrl, '');
|
|
18
|
+
return path.split('/').filter((p) => p !== '');
|
|
19
|
+
}
|
|
20
|
+
function removeVariablesFromPath(path) {
|
|
21
|
+
return path.replace(/{.+}/g, '');
|
|
22
|
+
}
|
|
23
|
+
function createBaseUrl(baseSegments) {
|
|
24
|
+
if (!baseSegments || baseSegments.length === 0)
|
|
25
|
+
return 'api';
|
|
26
|
+
if (baseSegments[0] === 'api')
|
|
27
|
+
return baseSegments.join('/');
|
|
28
|
+
return 'api/' + baseSegments.join('/');
|
|
29
|
+
}
|
|
30
|
+
function findCommonBaseUrl(paths) {
|
|
31
|
+
if (!paths || paths.length === 0)
|
|
32
|
+
return '';
|
|
33
|
+
if (paths.length === 1)
|
|
34
|
+
return pathWithoutVariables(paths[0].split('/'));
|
|
35
|
+
const splittedPaths = paths.map((p) => p.split('/'));
|
|
36
|
+
const firstPath = splittedPaths[0];
|
|
37
|
+
const commonSegments = [];
|
|
38
|
+
for (let i = 0; i < firstPath.length; i++) {
|
|
39
|
+
const segment = firstPath[i];
|
|
40
|
+
const isCommon = splittedPaths.every((p) => p[i] === segment);
|
|
41
|
+
if (isCommon) {
|
|
42
|
+
commonSegments.push(segment);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return pathWithoutVariables(commonSegments);
|
|
49
|
+
}
|
|
50
|
+
function pathWithoutVariables(segments) {
|
|
51
|
+
const firstVariableIndex = segments.findIndex((segment) => isVariable(segment));
|
|
52
|
+
if (firstVariableIndex !== -1) {
|
|
53
|
+
return segments.slice(0, firstVariableIndex).join('/');
|
|
54
|
+
}
|
|
55
|
+
return segments.join('/');
|
|
56
|
+
}
|
|
57
|
+
function standarizedPath(path) {
|
|
58
|
+
const splitted = path.split('/');
|
|
59
|
+
const filtered = splitted.filter((p) => p !== '').map((p) => p.toLowerCase());
|
|
60
|
+
return filtered.join('/');
|
|
61
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function kebabToCamelCase(str: string): string;
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param str :
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function kebabToPascalCase(str: string): string;
|
|
8
|
+
export declare function removeAllWhitespace(text: string): string;
|
|
9
|
+
export declare function lowerFirst(str: string): string;
|
|
10
|
+
export declare function upFirst(str: string): string;
|
|
11
|
+
export declare function toKebabCase(input: string): string;
|
|
12
|
+
export declare function normalizeSegment(segment: string): string;
|
|
13
|
+
export declare function toPascalCase(segments: string[]): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kebabToCamelCase = kebabToCamelCase;
|
|
4
|
+
exports.kebabToPascalCase = kebabToPascalCase;
|
|
5
|
+
exports.removeAllWhitespace = removeAllWhitespace;
|
|
6
|
+
exports.lowerFirst = lowerFirst;
|
|
7
|
+
exports.upFirst = upFirst;
|
|
8
|
+
exports.toKebabCase = toKebabCase;
|
|
9
|
+
exports.normalizeSegment = normalizeSegment;
|
|
10
|
+
exports.toPascalCase = toPascalCase;
|
|
11
|
+
function kebabToCamelCase(str) {
|
|
12
|
+
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param str :
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
function kebabToPascalCase(str) {
|
|
20
|
+
const camel = str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
21
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
22
|
+
}
|
|
23
|
+
function removeAllWhitespace(text) {
|
|
24
|
+
return text.replace(/\s+/g, '');
|
|
25
|
+
}
|
|
26
|
+
function lowerFirst(str) {
|
|
27
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
28
|
+
}
|
|
29
|
+
function upFirst(str) {
|
|
30
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
31
|
+
}
|
|
32
|
+
function toKebabCase(input) {
|
|
33
|
+
const transformedInput = input.replaceAll('Dto', '');
|
|
34
|
+
return (transformedInput.length > 0 ? transformedInput : input)
|
|
35
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
36
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
|
|
37
|
+
.toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
function normalizeSegment(segment) {
|
|
40
|
+
return segment
|
|
41
|
+
.split('-')
|
|
42
|
+
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
|
43
|
+
.join('');
|
|
44
|
+
}
|
|
45
|
+
function toPascalCase(segments) {
|
|
46
|
+
return segments.map(normalizeSegment).join('');
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kebabToCamelCase = kebabToCamelCase;
|
|
4
|
+
exports.kebabToPascalCase = kebabToPascalCase;
|
|
5
|
+
exports.toThisType = toThisType;
|
|
6
|
+
exports.lowerFirst = lowerFirst;
|
|
7
|
+
exports.upFirst = upFirst;
|
|
8
|
+
exports.toKebabCase = toKebabCase;
|
|
9
|
+
exports.normalizeSegment = normalizeSegment;
|
|
10
|
+
exports.toPascalCase = toPascalCase;
|
|
11
|
+
function kebabToCamelCase(str) {
|
|
12
|
+
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param str :
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
function kebabToPascalCase(str) {
|
|
20
|
+
const camel = str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
21
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
22
|
+
}
|
|
23
|
+
function toThisType(str) {
|
|
24
|
+
return kebabToPascalCase(str).replace(/s$/, "");
|
|
25
|
+
}
|
|
26
|
+
function lowerFirst(str) {
|
|
27
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
28
|
+
}
|
|
29
|
+
function upFirst(str) {
|
|
30
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
31
|
+
}
|
|
32
|
+
function toKebabCase(input) {
|
|
33
|
+
const transformedInput = input.replaceAll("Dto", "");
|
|
34
|
+
return (transformedInput.length > 0 ? transformedInput : input)
|
|
35
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
36
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
|
|
37
|
+
.toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
function normalizeSegment(segment) {
|
|
40
|
+
return segment
|
|
41
|
+
.split("-")
|
|
42
|
+
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
|
43
|
+
.join("");
|
|
44
|
+
}
|
|
45
|
+
function toPascalCase(segments) {
|
|
46
|
+
return segments.map(normalizeSegment).join("");
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
export declare function isReference(param: any): param is OpenAPIV3.ReferenceObject;
|
|
3
|
+
export declare function isParameterObject(param: any): param is OpenAPIV3.ParameterObject;
|
|
4
|
+
export declare function isNativeType(type: string): boolean;
|
|
5
|
+
export declare function isArrayType(type: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReference = isReference;
|
|
4
|
+
exports.isParameterObject = isParameterObject;
|
|
5
|
+
exports.isNativeType = isNativeType;
|
|
6
|
+
exports.isArrayType = isArrayType;
|
|
7
|
+
function isReference(param) {
|
|
8
|
+
return '$ref' in param;
|
|
9
|
+
}
|
|
10
|
+
function isParameterObject(param) {
|
|
11
|
+
return (param.in !== undefined &&
|
|
12
|
+
param.name !== undefined &&
|
|
13
|
+
param.schema !== undefined);
|
|
14
|
+
}
|
|
15
|
+
function isNativeType(type) {
|
|
16
|
+
const isArray = type.endsWith('[]');
|
|
17
|
+
let typeCopy = type;
|
|
18
|
+
if (isArray) {
|
|
19
|
+
typeCopy = type.replace('[]', '');
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
'string',
|
|
23
|
+
'number',
|
|
24
|
+
'boolean',
|
|
25
|
+
'any',
|
|
26
|
+
'void',
|
|
27
|
+
'Blob',
|
|
28
|
+
'generic',
|
|
29
|
+
'FormData',
|
|
30
|
+
'Date',
|
|
31
|
+
].includes(typeCopy);
|
|
32
|
+
}
|
|
33
|
+
function isArrayType(type) {
|
|
34
|
+
return type.endsWith('[]');
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swaggular",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"bin": {
|
|
7
|
+
"swaggular": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"serve": "npm run build && node dist/index.js",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
19
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"prepare": "husky"
|
|
22
|
+
},
|
|
23
|
+
"lint-staged": {
|
|
24
|
+
"src/**/*.ts": [
|
|
25
|
+
"eslint --fix",
|
|
26
|
+
"prettier --write"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"swagger",
|
|
31
|
+
"openapi",
|
|
32
|
+
"angular",
|
|
33
|
+
"typescript",
|
|
34
|
+
"code-generator"
|
|
35
|
+
],
|
|
36
|
+
"author": "",
|
|
37
|
+
"license": "ISC",
|
|
38
|
+
"type": "commonjs",
|
|
39
|
+
"description": "A tool to generate Angular services and models from Swagger/OpenAPI specifications.",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@eslint/js": "^10.0.1",
|
|
42
|
+
"@types/jest": "^30.0.0",
|
|
43
|
+
"@types/node": "^25.1.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.55.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.55.0",
|
|
46
|
+
"eslint": "^10.0.0",
|
|
47
|
+
"eslint-config-prettier": "^10.1.8",
|
|
48
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
49
|
+
"globals": "^17.3.0",
|
|
50
|
+
"husky": "^9.1.7",
|
|
51
|
+
"jest": "^30.2.0",
|
|
52
|
+
"lint-staged": "^16.2.7",
|
|
53
|
+
"prettier": "^3.8.1",
|
|
54
|
+
"ts-jest": "^29.4.6",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"typescript-eslint": "^8.55.0"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"openapi-types": "^12.1.3"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|