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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/app/get-parse-args.js +48 -0
  4. package/dist/app/parse-variables.js +24 -0
  5. package/dist/builders/build-comments.js +25 -0
  6. package/dist/cli/args.d.ts +2 -0
  7. package/dist/cli/args.js +48 -0
  8. package/dist/cli/variables.d.ts +2 -0
  9. package/dist/cli/variables.js +23 -0
  10. package/dist/core/state/interface-state.d.ts +17 -0
  11. package/dist/core/state/interface-state.js +21 -0
  12. package/dist/core/state/service-state.d.ts +9 -0
  13. package/dist/core/state/service-state.js +18 -0
  14. package/dist/core/state/swagger-state.d.ts +14 -0
  15. package/dist/core/state/swagger-state.js +36 -0
  16. package/dist/examples/services/get.example.js +1 -0
  17. package/dist/generators/generate-comments.js +40 -0
  18. package/dist/generators/generate-interface.js +219 -0
  19. package/dist/generators/generate-service.js +302 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +45 -0
  22. package/dist/models/file-content.js +2 -0
  23. package/dist/models/grouped-paths.js +2 -0
  24. package/dist/models/interface-data.js +2 -0
  25. package/dist/models/parsed-args.js +2 -0
  26. package/dist/models/service-data.js +2 -0
  27. package/dist/models/types.js +29 -0
  28. package/dist/parsers/path-grouper.d.ts +17 -0
  29. package/dist/parsers/path-grouper.js +207 -0
  30. package/dist/parsers/swagger-parser.d.ts +4 -0
  31. package/dist/parsers/swagger-parser.js +53 -0
  32. package/dist/renderers/generate-comments.d.ts +3 -0
  33. package/dist/renderers/generate-comments.js +40 -0
  34. package/dist/renderers/generate-interface.d.ts +12 -0
  35. package/dist/renderers/generate-interface.js +209 -0
  36. package/dist/renderers/generate-service.d.ts +9 -0
  37. package/dist/renderers/generate-service.js +178 -0
  38. package/dist/stores/interface-data-store.js +62 -0
  39. package/dist/stores/services-store.js +18 -0
  40. package/dist/stores/swagger-store.js +324 -0
  41. package/dist/templates/angular-template.js +23 -0
  42. package/dist/templates/paged-request-template.js +22 -0
  43. package/dist/templates/paged-result-template.js +13 -0
  44. package/dist/templates/services/angular-template.d.ts +15 -0
  45. package/dist/templates/services/angular-template.js +24 -0
  46. package/dist/templates/services/http-params-handler.d.ts +2 -0
  47. package/dist/templates/services/http-params-handler.js +12 -0
  48. package/dist/templates/types/extends-from-types.d.ts +3 -0
  49. package/dist/templates/types/extends-from-types.js +72 -0
  50. package/dist/templates/types/generic-types.d.ts +4 -0
  51. package/dist/templates/types/generic-types.js +72 -0
  52. package/dist/translators/add-import-to-interface.js +21 -0
  53. package/dist/translators/generate-interfaces.js +134 -0
  54. package/dist/translators/generate-services.js +192 -0
  55. package/dist/translators/join-with-templates.js +16 -0
  56. package/dist/translators/splitPaths.js +8 -0
  57. package/dist/types/file-content.d.ts +6 -0
  58. package/dist/types/file-content.js +2 -0
  59. package/dist/types/grouped-paths.d.ts +7 -0
  60. package/dist/types/grouped-paths.js +2 -0
  61. package/dist/types/interface-data.d.ts +13 -0
  62. package/dist/types/interface-data.js +2 -0
  63. package/dist/types/parsed-args.d.ts +9 -0
  64. package/dist/types/parsed-args.js +2 -0
  65. package/dist/types/service-data.d.ts +21 -0
  66. package/dist/types/service-data.js +2 -0
  67. package/dist/types/types.d.ts +23 -0
  68. package/dist/types/types.js +29 -0
  69. package/dist/utils/build-types.d.ts +2 -0
  70. package/dist/utils/build-types.js +66 -0
  71. package/dist/utils/create-file.d.ts +7 -0
  72. package/dist/utils/create-file.js +74 -0
  73. package/dist/utils/generate-imports.js +33 -0
  74. package/dist/utils/grouping-paths.js +68 -0
  75. package/dist/utils/method-builders.js +77 -0
  76. package/dist/utils/object-utils.d.ts +1 -0
  77. package/dist/utils/object-utils.js +11 -0
  78. package/dist/utils/path-utils.d.ts +7 -0
  79. package/dist/utils/path-utils.js +61 -0
  80. package/dist/utils/string-utils.d.ts +13 -0
  81. package/dist/utils/string-utils.js +47 -0
  82. package/dist/utils/to-case.js +47 -0
  83. package/dist/utils/type-guard.d.ts +5 -0
  84. package/dist/utils/type-guard.js +35 -0
  85. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Swagger to Angular Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Swaggular
2
+
3
+ A powerful tool to generate Angular services and models from Swagger/OpenAPI specifications.
4
+
5
+ ## Features
6
+
7
+ - 🚀 Automatically generates Angular services.
8
+ - 📦 Generates complex model interfaces.
9
+ - 📝 Includes JSDoc comments for better developer experience.
10
+ - 🛠️ Highly configurable.
11
+
12
+ ## Getting Started
13
+
14
+ ### Prerequisites
15
+
16
+ - Node.js (v18 or higher)
17
+ - npm or yarn
18
+
19
+ ### Installation
20
+
21
+ To install the tool globally:
22
+
23
+ ```bash
24
+ npm install -g swaggular
25
+ ```
26
+
27
+ Or run it directly using `npx`:
28
+
29
+ ```bash
30
+ npx swaggular --input=swagger.json
31
+ ```
32
+
33
+ ### Usage
34
+
35
+ Run the generator by providing the path to your Swagger/OpenAPI file:
36
+
37
+ ```bash
38
+ swaggular --input=path/to/your/swagger.json
39
+ ```
40
+
41
+ #### Options
42
+
43
+ - `--input`: Path to the swagger.json file (required).
44
+ - `--ignore-segments`: Path segments to ignore when generating service names.
45
+ - `--no-generate`: Parse the file but don't generate the output.
46
+
47
+ The generated files will be available in the `results` folder.
48
+
49
+ ## Development
50
+
51
+ ### Scripts
52
+
53
+ - `npm run build`: Compile TypeScript to JavaScript.
54
+ - `npm run start`: Run the compiled project.
55
+ - `npm run serve`: Compile and run the project immediately.
56
+ - `npm run lint`: Run ESLint to check code style.
57
+ - `npm run format`: Format code using Prettier.
58
+ - `npm test`: Run tests using Jest.
59
+
60
+ ## Contributing
61
+
62
+ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
63
+
64
+ ## License
65
+
66
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParseArgs = getParseArgs;
4
+ function getParseArgs(argv) {
5
+ const args = {};
6
+ const positional = [];
7
+ for (let i = 0; i < argv.length; i++) {
8
+ const arg = argv[i];
9
+ if (arg.startsWith("--") && arg.includes("=")) {
10
+ const [k, v] = arg.slice(2).split("=");
11
+ args[k] = v;
12
+ continue;
13
+ }
14
+ if (arg.startsWith("--")) {
15
+ const k = arg.slice(2);
16
+ const next = argv[i + 1];
17
+ if (!next || next.startsWith("-")) {
18
+ args[k] = true;
19
+ }
20
+ else {
21
+ args[k] = next;
22
+ i++;
23
+ }
24
+ continue;
25
+ }
26
+ if (arg.startsWith("-") && arg.length > 2) {
27
+ arg
28
+ .slice(1)
29
+ .split("")
30
+ .forEach((k) => (args[k] = true));
31
+ continue;
32
+ }
33
+ if (arg.startsWith("-")) {
34
+ const k = arg.slice(1);
35
+ const next = argv[i + 1];
36
+ if (!next || next.startsWith("-")) {
37
+ args[k] = true;
38
+ }
39
+ else {
40
+ args[k] = next;
41
+ i++;
42
+ }
43
+ continue;
44
+ }
45
+ positional.push(arg);
46
+ }
47
+ return { args, positional };
48
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toVariables = toVariables;
4
+ function toVariables(parsed) {
5
+ const variables = {};
6
+ if (parsed.args.mode) {
7
+ variables.groupingMode = parsed.args.mode;
8
+ }
9
+ if (parsed.args.segmentsToIgnore) {
10
+ if (typeof parsed.args.segmentsToIgnore === "string") {
11
+ variables.segmentsToIgnore = parsed.args.segmentsToIgnore.split(",");
12
+ }
13
+ }
14
+ if (parsed.args.ignoreVariables) {
15
+ variables.ignoreVariables =
16
+ parsed.args.ignoreVariables === "true" ||
17
+ parsed.args.ignoreVariables === true;
18
+ }
19
+ return {
20
+ groupingMode: variables.groupingMode || "path",
21
+ segmentsToIgnore: variables.segmentsToIgnore || ["api"],
22
+ ignoreVariables: variables.ignoreVariables || true,
23
+ };
24
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildComments = buildComments;
4
+ function buildComments(param) {
5
+ const comments = [];
6
+ if (param.format !== undefined) {
7
+ comments.push(`format: ${param.format}`);
8
+ }
9
+ if (param.minLength !== undefined) {
10
+ comments.push(`minLength: ${param.minLength}`);
11
+ }
12
+ if (param.maxLength !== undefined) {
13
+ comments.push(`maxLength: ${param.maxLength}`);
14
+ }
15
+ if (param.minimum !== undefined) {
16
+ comments.push(`minimum: ${param.minimum}`);
17
+ }
18
+ if (param.maximum !== undefined) {
19
+ comments.push(`maximum: ${param.maximum}`);
20
+ }
21
+ if (comments.length > 0) {
22
+ return ` /**\n * ${comments.join("\n * ")}\n */`;
23
+ }
24
+ return "";
25
+ }
@@ -0,0 +1,2 @@
1
+ import { ParsedArgs } from '../types/parsed-args';
2
+ export declare function getParseArgs(argv: string[]): ParsedArgs;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParseArgs = getParseArgs;
4
+ function getParseArgs(argv) {
5
+ const args = {};
6
+ const positional = [];
7
+ for (let i = 0; i < argv.length; i++) {
8
+ const arg = argv[i];
9
+ if (arg.startsWith('--') && arg.includes('=')) {
10
+ const [k, v] = arg.slice(2).split('=');
11
+ args[k] = v;
12
+ continue;
13
+ }
14
+ if (arg.startsWith('--')) {
15
+ const k = arg.slice(2);
16
+ const next = argv[i + 1];
17
+ if (!next || next.startsWith('-')) {
18
+ args[k] = true;
19
+ }
20
+ else {
21
+ args[k] = next;
22
+ i++;
23
+ }
24
+ continue;
25
+ }
26
+ if (arg.startsWith('-') && arg.length > 2) {
27
+ arg
28
+ .slice(1)
29
+ .split('')
30
+ .forEach((k) => (args[k] = true));
31
+ continue;
32
+ }
33
+ if (arg.startsWith('-')) {
34
+ const k = arg.slice(1);
35
+ const next = argv[i + 1];
36
+ if (!next || next.startsWith('-')) {
37
+ args[k] = true;
38
+ }
39
+ else {
40
+ args[k] = next;
41
+ i++;
42
+ }
43
+ continue;
44
+ }
45
+ positional.push(arg);
46
+ }
47
+ return { args, positional };
48
+ }
@@ -0,0 +1,2 @@
1
+ import { ArgsVariables, ParsedArgs } from '../types/parsed-args';
2
+ export declare function toVariables(parsed: ParsedArgs): ArgsVariables;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toVariables = toVariables;
4
+ function toVariables(parsed) {
5
+ const variables = {};
6
+ if (parsed.args.mode) {
7
+ variables.groupingMode = parsed.args.mode;
8
+ }
9
+ if (parsed.args.segmentsToIgnore) {
10
+ if (typeof parsed.args.segmentsToIgnore === 'string') {
11
+ variables.segmentsToIgnore = parsed.args.segmentsToIgnore.split(',');
12
+ }
13
+ }
14
+ if (parsed.args.ignoreVariables) {
15
+ variables.ignoreVariables =
16
+ parsed.args.ignoreVariables === 'true' || parsed.args.ignoreVariables === true;
17
+ }
18
+ return {
19
+ groupingMode: variables.groupingMode || 'path',
20
+ segmentsToIgnore: variables.segmentsToIgnore || ['api'],
21
+ ignoreVariables: variables.ignoreVariables || true,
22
+ };
23
+ }
@@ -0,0 +1,17 @@
1
+ import { IJsonSchema } from 'openapi-types';
2
+ import { InterfaceData } from '../../types/interface-data';
3
+ export interface InterfaceStateI {
4
+ generatedInterfaces: Record<string, InterfaceData>;
5
+ generatedEnums: Record<string, InterfaceData>;
6
+ }
7
+ declare class InterfaceState implements InterfaceStateI {
8
+ generatedInterfaces: Record<string, InterfaceData>;
9
+ generatedEnums: Record<string, InterfaceData>;
10
+ componentsSchemas: Record<string, IJsonSchema>;
11
+ constructor();
12
+ setComponentsSchemas(componentsSchemas: Record<string, IJsonSchema>): void;
13
+ getComponentsSchema(name: string): IJsonSchema | undefined;
14
+ addInterfaces(interfacesData: InterfaceData[]): void;
15
+ }
16
+ export declare const interfaceState: InterfaceState;
17
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interfaceState = void 0;
4
+ class InterfaceState {
5
+ generatedInterfaces = {};
6
+ generatedEnums = {};
7
+ componentsSchemas = {};
8
+ constructor() { }
9
+ setComponentsSchemas(componentsSchemas) {
10
+ this.componentsSchemas = componentsSchemas;
11
+ }
12
+ getComponentsSchema(name) {
13
+ return this.componentsSchemas[name];
14
+ }
15
+ addInterfaces(interfacesData) {
16
+ for (const inter of interfacesData) {
17
+ this.generatedInterfaces[inter.name] = inter;
18
+ }
19
+ }
20
+ }
21
+ exports.interfaceState = new InterfaceState();
@@ -0,0 +1,9 @@
1
+ import { ServiceData } from '../../types/service-data';
2
+ declare class ServiceState {
3
+ services: Record<string, ServiceData>;
4
+ addService(name: string, content: ServiceData): void;
5
+ addServices(services: ServiceData[]): void;
6
+ getService(name: string): ServiceData | undefined;
7
+ }
8
+ export declare const serviceState: ServiceState;
9
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serviceState = void 0;
4
+ class ServiceState {
5
+ services = {};
6
+ addService(name, content) {
7
+ this.services[name] = content;
8
+ }
9
+ addServices(services) {
10
+ services.forEach((service) => {
11
+ this.services[service.name] = service;
12
+ });
13
+ }
14
+ getService(name) {
15
+ return this.services[name];
16
+ }
17
+ }
18
+ exports.serviceState = new ServiceState();
@@ -0,0 +1,14 @@
1
+ import { OpenAPIV3 } from 'openapi-types';
2
+ import { GroupedPaths } from '../../types/grouped-paths';
3
+ export declare class SwaggerState {
4
+ private swagger;
5
+ private pathsGroupedByScope;
6
+ setSwagger(swagger: OpenAPIV3.Document): void;
7
+ getSwagger(): OpenAPIV3.Document | undefined;
8
+ setPathsGroupedByScope(pathsGroupedByScope: GroupedPaths): void;
9
+ getPaths(): OpenAPIV3.PathsObject | undefined;
10
+ getSchemas(): Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject> | undefined;
11
+ getPathsGroupedByScope(): GroupedPaths | undefined;
12
+ getGroupByPath(path: string): import("../../types/grouped-paths").GroupedPath | undefined;
13
+ }
14
+ export declare const swaggerState: SwaggerState;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swaggerState = exports.SwaggerState = void 0;
4
+ class SwaggerState {
5
+ swagger = undefined;
6
+ pathsGroupedByScope = undefined;
7
+ setSwagger(swagger) {
8
+ this.swagger = swagger;
9
+ }
10
+ getSwagger() {
11
+ return this.swagger;
12
+ }
13
+ setPathsGroupedByScope(pathsGroupedByScope) {
14
+ this.pathsGroupedByScope = pathsGroupedByScope;
15
+ }
16
+ getPaths() {
17
+ return this.swagger?.paths;
18
+ }
19
+ getSchemas() {
20
+ return this.swagger?.components?.schemas;
21
+ }
22
+ getPathsGroupedByScope() {
23
+ return this.pathsGroupedByScope;
24
+ }
25
+ getGroupByPath(path) {
26
+ if (!this.pathsGroupedByScope)
27
+ return;
28
+ for (const value of Object.values(this.pathsGroupedByScope)) {
29
+ if (value.paths.includes(path))
30
+ return value;
31
+ }
32
+ return undefined;
33
+ }
34
+ }
35
+ exports.SwaggerState = SwaggerState;
36
+ exports.swaggerState = new SwaggerState();
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateInterfaceComments = generateInterfaceComments;
4
+ exports.generateServiceComments = generateServiceComments;
5
+ function generateInterfaceComments(param) {
6
+ const comments = [];
7
+ if (param.format !== undefined) {
8
+ comments.push(`format: ${param.format}`);
9
+ }
10
+ if (param.minLength !== undefined) {
11
+ comments.push(`minLength: ${param.minLength}`);
12
+ }
13
+ if (param.maxLength !== undefined) {
14
+ comments.push(`maxLength: ${param.maxLength}`);
15
+ }
16
+ if (param.minimum !== undefined) {
17
+ comments.push(`minimum: ${param.minimum}`);
18
+ }
19
+ if (param.maximum !== undefined) {
20
+ comments.push(`maximum: ${param.maximum}`);
21
+ }
22
+ if (comments.length > 0) {
23
+ return ` /**\n * ${comments.join("\n * ")}\n */`;
24
+ }
25
+ return "";
26
+ }
27
+ function generateServiceComments(summary, responseType, parameters) {
28
+ const summarySplited = [];
29
+ for (let i = 0; i < summary.length; i += 100) {
30
+ summarySplited.push(summary.slice(i, i + 100));
31
+ }
32
+ const comments = summarySplited;
33
+ if (parameters && parameters.length > 0) {
34
+ comments.push(`${parameters.map((p) => `\t\t @param ${p.name} : ${p.type}`).join("\n")}`);
35
+ }
36
+ if (responseType) {
37
+ comments.push(`\t\t @returns Observable<${responseType}>`);
38
+ }
39
+ return `/**\n${comments.map((c) => `\t\t* ${c}\n`).join("")}\n */`;
40
+ }
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parametersToIProperties = parametersToIProperties;
4
+ exports.propertiesToIProperties = propertiesToIProperties;
5
+ exports.generateInterfaces = generateInterfaces;
6
+ exports.generateWithParameters = generateWithParameters;
7
+ exports.computeParametersName = computeParametersName;
8
+ exports.generateComponentsSchemas = generateComponentsSchemas;
9
+ exports.generateInterfacesFiles = generateInterfacesFiles;
10
+ exports.generateContent = generateContent;
11
+ const interface_data_store_1 = require("../stores/interface-data-store");
12
+ const swagger_store_1 = require("../stores/swagger-store");
13
+ const extends_from_types_1 = require("../templates/types/extends-from-types");
14
+ const generic_types_1 = require("../templates/types/generic-types");
15
+ const build_types_1 = require("../utils/build-types");
16
+ const object_utils_1 = require("../utils/object-utils");
17
+ const path_utils_1 = require("../utils/path-utils");
18
+ const string_utils_1 = require("../utils/string-utils");
19
+ const type_guard_1 = require("../utils/type-guard");
20
+ const generate_comments_1 = require("./generate-comments");
21
+ function parametersToIProperties(parameters) {
22
+ const properties = [];
23
+ for (const param of parameters) {
24
+ if ((0, type_guard_1.isReference)(param)) {
25
+ const ref = param.$ref.split("/").pop();
26
+ properties.push({
27
+ name: (0, string_utils_1.lowerFirst)(ref),
28
+ type: ref,
29
+ optional: false,
30
+ comments: "",
31
+ });
32
+ continue;
33
+ }
34
+ if (param.in !== "query")
35
+ continue;
36
+ const tsType = (0, build_types_1.switchTypeJson)(param.schema);
37
+ properties.push({
38
+ name: (0, string_utils_1.lowerFirst)(param.name),
39
+ type: tsType,
40
+ optional: !param.required,
41
+ comments: (0, generate_comments_1.generateInterfaceComments)(param.schema),
42
+ });
43
+ }
44
+ return properties;
45
+ }
46
+ function propertiesToIProperties(properties) {
47
+ const interfaceDataProperties = [];
48
+ for (const [name, property] of Object.entries(properties)) {
49
+ if ((0, type_guard_1.isReference)(property)) {
50
+ const ref = property.$ref.split("/").pop();
51
+ interfaceDataProperties.push({
52
+ name,
53
+ type: ref,
54
+ optional: false,
55
+ comments: "",
56
+ });
57
+ continue;
58
+ }
59
+ interfaceDataProperties.push({
60
+ name,
61
+ type: (0, build_types_1.switchTypeJson)(property),
62
+ optional: property.nullable ?? false,
63
+ comments: (0, generate_comments_1.generateInterfaceComments)(property),
64
+ });
65
+ }
66
+ return interfaceDataProperties;
67
+ }
68
+ function generateInterfaces() {
69
+ generateComponentsSchemas();
70
+ generateWithParameters();
71
+ }
72
+ function generateWithParameters() {
73
+ const paths = swagger_store_1.swaggerStore.getPaths();
74
+ const groupedPaths = swagger_store_1.swaggerStore.getPathsGroupedByScope();
75
+ if (!paths || !groupedPaths)
76
+ return;
77
+ const interfacesData = [];
78
+ for (const groupedPath of Object.values(groupedPaths)) {
79
+ for (const innerPath of groupedPath.paths) {
80
+ const pathInfo = paths[innerPath];
81
+ if (!pathInfo)
82
+ continue;
83
+ const methods = (0, object_utils_1.removeFalsyValues)({
84
+ get: pathInfo.get,
85
+ post: pathInfo.post,
86
+ put: pathInfo.put,
87
+ delete: pathInfo.delete,
88
+ patch: pathInfo.patch,
89
+ });
90
+ for (const [httpMethod, pathData] of Object.entries(methods)) {
91
+ if (!pathData?.parameters)
92
+ continue;
93
+ const parameters = pathData.parameters;
94
+ const properties = parametersToIProperties(parameters);
95
+ if (properties.length === 0)
96
+ continue;
97
+ const interfaceName = computeParametersName(httpMethod, innerPath, groupedPath);
98
+ const interData = {
99
+ name: interfaceName,
100
+ type: "interface",
101
+ imports: properties
102
+ .filter((p) => !(0, type_guard_1.isNativeType)(p.type))
103
+ .map((p) => p.type),
104
+ properties,
105
+ };
106
+ const generic = (0, generic_types_1.isGenericType)(interData);
107
+ if (generic)
108
+ continue;
109
+ const interDataWithExtendsFrom = (0, extends_from_types_1.computeExtendsFromType)(interData);
110
+ interfacesData.push(interDataWithExtendsFrom);
111
+ }
112
+ }
113
+ }
114
+ interface_data_store_1.interfaceDataStore.addInterfaces(interfacesData);
115
+ }
116
+ function computeParametersName(method, innerPath, groupedPath) {
117
+ const dict = {
118
+ get: "",
119
+ post: "Create",
120
+ put: "Update",
121
+ delete: "Delete",
122
+ patch: "Patch",
123
+ };
124
+ const name = dict[method];
125
+ const extra = (0, string_utils_1.kebabToPascalCase)((0, path_utils_1.removeVariablesFromPath)((0, path_utils_1.getExtraSegments)(innerPath, (0, path_utils_1.createBaseUrl)(groupedPath.baseSegments)).join("")));
126
+ return name + groupedPath.groupName + (0, string_utils_1.upFirst)(extra) + "Params";
127
+ }
128
+ function generateComponentsSchemas() {
129
+ const schemas = swagger_store_1.swaggerStore.getSchemas();
130
+ if (!schemas)
131
+ return;
132
+ const interfaces = [];
133
+ for (const [key, value] of Object.entries(schemas)) {
134
+ if ((0, type_guard_1.isReference)(value))
135
+ continue;
136
+ if (!value.properties) {
137
+ if (value.enum) {
138
+ const interData = {
139
+ name: key,
140
+ type: "enum",
141
+ imports: [],
142
+ properties: value.enum.map((e) => {
143
+ return {
144
+ name: e,
145
+ type: e,
146
+ optional: false,
147
+ comments: "",
148
+ };
149
+ }),
150
+ };
151
+ interfaces.push(interData);
152
+ }
153
+ continue;
154
+ }
155
+ const properties = propertiesToIProperties(value.properties);
156
+ const interData = {
157
+ name: key,
158
+ type: "interface",
159
+ imports: properties
160
+ .filter((p) => !(0, type_guard_1.isNativeType)(p.type))
161
+ .map((p) => p.type),
162
+ properties,
163
+ };
164
+ const generic = (0, generic_types_1.isGenericType)(interData);
165
+ if (generic) {
166
+ continue;
167
+ }
168
+ const interDataWithExtendsFrom = (0, extends_from_types_1.computeExtendsFromType)(interData);
169
+ interfaces.push(interDataWithExtendsFrom);
170
+ }
171
+ interface_data_store_1.interfaceDataStore.addInterfaces(interfaces);
172
+ }
173
+ function generateInterfacesFiles(locations) {
174
+ const interfacesData = [
175
+ ...generic_types_1.genericTypesData,
176
+ ...extends_from_types_1.extendsFromTypes,
177
+ ...Array.from(Object.values(interface_data_store_1.interfaceDataStore.generatedInterfaces)),
178
+ ];
179
+ const filesContent = [];
180
+ for (const [key, value] of Object.entries(interfacesData)) {
181
+ const location = [
182
+ value.type === "enum" ? "enums" : "dtos",
183
+ ...(locations?.[key] ?? []),
184
+ ];
185
+ const content = generateContent(value, location.length);
186
+ const extraName = value.type === "enum" ? "enum" : "dto";
187
+ filesContent.push({
188
+ location: location,
189
+ content,
190
+ extension: "ts",
191
+ name: (0, string_utils_1.toKebabCase)(value.name) + `.${extraName}`,
192
+ });
193
+ }
194
+ return filesContent;
195
+ }
196
+ generateContent;
197
+ function generateContent(interfaceData, deep = 0) {
198
+ const imports = [...interfaceData.imports];
199
+ const importsTemplate = imports.length > 0
200
+ ? `import { ${imports.join(", ")} } from "${"../".repeat(deep)}models";`
201
+ : "";
202
+ if (interfaceData.type === "interface") {
203
+ const content = `${importsTemplate}\n\nexport interface ${interfaceData.name} ${interfaceData.extendsFrom && interfaceData.extendsFrom.length > 0 ? `extends ${interfaceData.extendsFrom.join(", ")}` : ""} {
204
+ ${interfaceData.properties
205
+ .map((p) => `${p.comments}\n\t${(0, string_utils_1.lowerFirst)(p.name)}${p.optional ? "?" : ""}: ${p.type};`)
206
+ .join("\n")}
207
+ }`;
208
+ return content;
209
+ }
210
+ if (interfaceData.type === "enum") {
211
+ const content = `export enum ${interfaceData.name} {
212
+ ${interfaceData.properties
213
+ .map((p) => `${p.comments}\n\t${p.name} = '${p.type}',`)
214
+ .join("\n")}
215
+ }`;
216
+ return content;
217
+ }
218
+ return "";
219
+ }