@devlearning/swagger-generator 1.0.23 → 1.0.25

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 (77) hide show
  1. package/.vscode/launch.json +22 -22
  2. package/README.md +209 -209
  3. package/autogen/identity/api/identity_api.dart +100 -99
  4. package/autogen/identity/models/auth_activate_command.dart +14 -14
  5. package/autogen/identity/models/auth_app_authenticate_command.dart +16 -16
  6. package/autogen/identity/models/auth_generate_reset_password_code_command.dart +15 -15
  7. package/autogen/identity/models/auth_refresh_token_command.dart +15 -15
  8. package/autogen/identity/models/auth_reset_password_command.dart +16 -16
  9. package/autogen/identity/models/auth_user_authenticate_command.dart +15 -15
  10. package/autogen/identity/models/auth_user_dto.dart +18 -18
  11. package/autogen/identity/models/auth_verify_reset_password_code_command.dart +14 -14
  12. package/autogen/identity/models/authentication_token.dart +17 -17
  13. package/autogen/mvc/models/problem_details.dart +17 -17
  14. package/autogen/product/api/product_api.dart +70 -0
  15. package/autogen/product/models/geoposition.dart +14 -0
  16. package/autogen/product/models/product_category_dto.dart +15 -0
  17. package/autogen/product/models/product_category_list_query_response.dart +14 -0
  18. package/autogen/product/models/product_category_save_command.dart +15 -0
  19. package/autogen/product/models/product_list_nearby_query.dart +20 -0
  20. package/autogen/product/models/product_list_nearby_query_filter.dart +15 -0
  21. package/autogen/product/models/product_list_nearby_query_order_by.dart +10 -0
  22. package/autogen/product/models/product_save_command.dart +13 -0
  23. package/autogen/service_defaults/models/application_exception.dart +14 -14
  24. package/autogen/service_defaults/models/result.dart +17 -17
  25. package/autogen/service_defaults/models/sort_direction.dart +10 -0
  26. package/autogen/user_profile/api/user_profile_api.dart +51 -60
  27. package/autogen/user_profile/models/user_general_info_save_command.dart +17 -13
  28. package/dist/api.constants.js +22 -22
  29. package/dist/generator.js +9 -4
  30. package/dist/generators-writers/angular/api-angular-writer.js +15 -15
  31. package/dist/generators-writers/angular/constants.js +24 -24
  32. package/dist/generators-writers/angular/model-angular-writer.js +6 -6
  33. package/dist/generators-writers/dart/api-dart-writer.js +5 -1
  34. package/dist/generators-writers/dart/model-dart-writer.js +63 -60
  35. package/dist/generators-writers/dart/templates/api.mustache +36 -34
  36. package/dist/generators-writers/dart/templates/enum.mustache +14 -0
  37. package/dist/generators-writers/dart/templates/model.mustache +18 -18
  38. package/dist/generators-writers/nextjs/api-nextjs-writer.js +12 -12
  39. package/dist/generators-writers/nextjs/constants.js +4 -4
  40. package/dist/generators-writers/nextjs/model-nextjs-writer.js +6 -6
  41. package/package.json +45 -45
  42. package/src/api.constants.ts +26 -26
  43. package/src/generator-old.ts +449 -449
  44. package/src/generator.ts +582 -577
  45. package/src/generators-writers/angular/api-angular-writer.ts +141 -141
  46. package/src/generators-writers/angular/constants.ts +36 -36
  47. package/src/generators-writers/angular/model-angular-writer.ts +62 -62
  48. package/src/generators-writers/dart/api-dart-writer.ts +190 -185
  49. package/src/generators-writers/dart/model-dart-writer.ts +162 -143
  50. package/src/generators-writers/dart/models/import-definition-dart.ts +5 -5
  51. package/src/generators-writers/dart/normalizator.ts +72 -72
  52. package/src/generators-writers/dart/templates/api.mustache +36 -34
  53. package/src/generators-writers/dart/templates/enum.mustache +14 -0
  54. package/src/generators-writers/dart/templates/model.mustache +18 -18
  55. package/src/generators-writers/nextjs/api-nextjs-writer.ts +156 -156
  56. package/src/generators-writers/nextjs/constants.ts +5 -5
  57. package/src/generators-writers/nextjs/model-nextjs-writer.ts +61 -61
  58. package/src/generators-writers/utils.ts +78 -78
  59. package/src/index.ts +96 -96
  60. package/src/models/api-dto.ts +17 -17
  61. package/src/models/enum-value-dto.ts +3 -3
  62. package/src/models/model-dto.ts +9 -9
  63. package/src/models/parameter-dto.ts +7 -7
  64. package/src/models/property-dto.ts +4 -4
  65. package/src/models/swagger/swagger-component-property.ts +11 -11
  66. package/src/models/swagger/swagger-component.ts +17 -17
  67. package/src/models/swagger/swagger-content.ts +4 -4
  68. package/src/models/swagger/swagger-info.ts +3 -3
  69. package/src/models/swagger/swagger-method.ts +7 -7
  70. package/src/models/swagger/swagger-schema.ts +20 -20
  71. package/src/models/swagger/swagger.ts +38 -38
  72. package/src/models/type-dto.ts +7 -7
  73. package/src/swagger-downloader.ts +12 -12
  74. package/tsconfig.json +28 -28
  75. package/autogen/user_profile/models/test_save_command.dart +0 -13
  76. package/dist/templates/api.mustache +0 -29
  77. package/dist/templates/model.mustache +0 -18
@@ -1,186 +1,191 @@
1
- import fs, { writeFileSync } from 'fs';
2
- import { ApiDto } from '@src/models/api-dto.js';
3
- import { Utils } from '../utils.js';
4
- import { ParameterDto } from '@src/models/parameter-dto.js';
5
- import * as Mustache from 'mustache';
6
- import { CommandLineArgs } from '@src/index.js';
7
- import { ModelDto } from '@src/models/model-dto.js';
8
- import { TypeDto } from '@src/models/type-dto.js';
9
- import { ImportDefinitionDart } from './models/import-definition-dart.js';
10
- import { Normalizator } from './normalizator.js';
11
- import path from 'path';
12
- import { fileURLToPath } from 'url';
13
-
14
- interface ApiDefinitionDart {
15
- package: string;
16
- outputDirectory: string;
17
- filename: string;
18
- apiClassName: string;
19
- imports: string[];
20
- endpoints: EndpointDefinitionDart[];
21
- }
22
-
23
- interface EndpointDefinitionDart {
24
- methodName: string;
25
- httpMethod: HttpMethodDart;
26
- path: string;
27
- responseType: string;
28
- haveRequest: boolean;
29
- requestType?: string; // solo se haveRequest è true
30
- queryParams?: Parameter[],
31
- }
32
-
33
- interface Parameter {
34
- name: string;
35
- type: string; // "string", "int", ecc
36
- nullable: boolean;
37
- }
38
-
39
- type HttpMethodDart = 'get' | 'post' | 'put' | 'delete' | 'patch';
40
-
41
-
42
- export class ApiDartWriter {
43
- private _commandLineArgs: CommandLineArgs;
44
-
45
- constructor(commandLineArgs: CommandLineArgs) {
46
- this._commandLineArgs = commandLineArgs;
47
- }
48
-
49
- write(apis: ApiDto[], models: ModelDto[]) {
50
- const __filename = fileURLToPath(import.meta.url);
51
- const __dirname = path.dirname(__filename);
52
- const templatePath = path.join(__dirname, 'templates', 'api.mustache');
53
- const template = fs.readFileSync(templatePath, 'utf-8');
54
- let importDirectory = this._commandLineArgs.outputDirectory;
55
- if (importDirectory.startsWith('lib/')) {
56
- importDirectory = importDirectory.slice('lib/'.length);
57
- }
58
-
59
- const grouped = this._groupByTag(apis);
60
-
61
- for (const [tag, apis] of Object.entries(grouped)) {
62
- console.log(`Api: ${tag}`);
63
-
64
- let subPath = '';
65
- let filename = '';
66
- let apiClassName = '';
67
-
68
- subPath = Utils.toDartFileName(tag);
69
- filename = `${Utils.toDartFileName(tag + 'Api')}`;
70
- apiClassName = `${Utils.toDartClassName(tag + 'Api')}`;
71
-
72
- var apiDefinition = <ApiDefinitionDart>{
73
- package: this._commandLineArgs.package,
74
- outputDirectory: this._commandLineArgs.outputDirectory,
75
- filename: filename,
76
- apiClassName: apiClassName,
77
- }
78
-
79
- var endpoints = <EndpointDefinitionDart[]>[];
80
- var imports = <ImportDefinitionDart[]>[];
81
-
82
- for (const api of apis) {
83
- var requestType: string | undefined = undefined;
84
- requestType = api.haveRequest ? api.parameters[0]?.typeName || 'void' : undefined;
85
- requestType = requestType?.split('.').pop()!
86
- requestType = Utils.toDartClassName(requestType);
87
-
88
- var responseType: string = 'void';
89
- responseType = api.returnType ? api.returnType.typeName : 'void';
90
- responseType = responseType?.split('.').pop()!;
91
- responseType = Utils.toDartClassName(responseType) ?? responseType;
92
-
93
- var methodName = Utils.getNormalizedApiPath(api.name);
94
- if (methodName.startsWith(Utils.toFirstLetterLowercase(tag))) {
95
- methodName = methodName.slice(tag.length);
96
- methodName = Utils.toFirstLetterLowercase(methodName);
97
- }
98
-
99
- const endpoint = <EndpointDefinitionDart>{
100
- methodName: methodName,
101
- httpMethod: api.method.toLowerCase() as HttpMethodDart,
102
- path: api.url,
103
- responseType: responseType,
104
- haveRequest: api.haveRequest,
105
- requestType: requestType,
106
- };
107
-
108
- if (api.parameters && api.parameters.length > 0) {
109
- endpoint.queryParams = api.parameters
110
- .map(p => ({
111
- name: p.name,
112
- type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName)! : 'String',
113
- nullable: p.nullable
114
- }));
115
- }
116
-
117
- if (api.haveRequest && api.parameters[0]?.typeName) {
118
- if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
119
- models.forEach(model => {
120
- if (model.typeName === api.parameters[0]?.typeName) {
121
- const normalizedInfo = Normalizator.getNormalizedInfo(model);
122
- imports.push({
123
- type: api.parameters[0],
124
- import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
125
- });
126
- }
127
- });
128
- }
129
- }
130
-
131
- if (api.returnType && !api.returnType.isNativeType) {
132
- if (imports.findIndex(x => x.type.typeName == api.returnType!.typeName) == -1) {
133
- models.forEach(model => {
134
- if (model.typeName === api.returnType!.typeName) {
135
- const normalizedInfo = Normalizator.getNormalizedInfo(model);
136
- imports.push({
137
- type: api.returnType!,
138
- import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
139
- });
140
- }
141
- });
142
- }
143
- }
144
-
145
- endpoints.push(endpoint);
146
- }
147
-
148
- apiDefinition.endpoints = endpoints;
149
- apiDefinition.imports = imports.map(i => i.import);
150
-
151
- let destinationPath = `${this._commandLineArgs.outputDirectory}/${subPath}/api`;
152
-
153
- Utils.ensureDirectorySync(`${destinationPath}`);
154
-
155
- var result = Mustache.default.render(template, apiDefinition);
156
- writeFileSync(`${destinationPath}/${apiDefinition.filename}.dart`, result, 'utf-8');
157
- }
158
- }
159
-
160
- private _toPascalCase(input: string): string {
161
- return input
162
- .replace(/[_\- ]+/g, ' ') // sostituisce underscore, dash e spazi con uno spazio singolo
163
- .trim() // rimuove spazi iniziali/finali
164
- .split(' ') // divide in parole
165
- .map(word =>
166
- word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
167
- )
168
- .join('');
169
- }
170
-
171
- private _normalizeApiClassName(input: string): string {
172
- return input
173
- .replace(/\./g, '');
174
- }
175
-
176
- private _groupByTag(apis: ApiDto[]) {
177
- const groupedByRole = apis.reduce<Record<string, ApiDto[]>>((acc, api) => {
178
- if (!acc[api.tag]) {
179
- acc[api.tag] = [];
180
- }
181
- acc[api.tag].push(api);
182
- return acc;
183
- }, {});
184
- return groupedByRole;
185
- }
1
+ import fs, { writeFileSync } from 'fs';
2
+ import { ApiDto } from '@src/models/api-dto.js';
3
+ import { Utils } from '../utils.js';
4
+ import { ParameterDto } from '@src/models/parameter-dto.js';
5
+ import * as Mustache from 'mustache';
6
+ import { CommandLineArgs } from '@src/index.js';
7
+ import { ModelDto } from '@src/models/model-dto.js';
8
+ import { TypeDto } from '@src/models/type-dto.js';
9
+ import { ImportDefinitionDart } from './models/import-definition-dart.js';
10
+ import { Normalizator } from './normalizator.js';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+
14
+ interface ApiDefinitionDart {
15
+ package: string;
16
+ outputDirectory: string;
17
+ filename: string;
18
+ apiClassName: string;
19
+ imports: string[];
20
+ endpoints: EndpointDefinitionDart[];
21
+ }
22
+
23
+ interface EndpointDefinitionDart {
24
+ methodName: string;
25
+ httpMethod: HttpMethodDart;
26
+ path: string;
27
+ responseType: string;
28
+ haveRequest: boolean;
29
+ requestType?: string; // solo se haveRequest è true
30
+ queryParams?: Parameter[],
31
+ }
32
+
33
+ interface Parameter {
34
+ name: string;
35
+ type: string; // "string", "int", ecc
36
+ nullable: boolean;
37
+ }
38
+
39
+ type HttpMethodDart = 'get' | 'post' | 'put' | 'delete' | 'patch';
40
+
41
+
42
+ export class ApiDartWriter {
43
+ private _commandLineArgs: CommandLineArgs;
44
+
45
+ constructor(commandLineArgs: CommandLineArgs) {
46
+ this._commandLineArgs = commandLineArgs;
47
+ }
48
+
49
+ write(apis: ApiDto[], models: ModelDto[]) {
50
+ const __filename = fileURLToPath(import.meta.url);
51
+ const __dirname = path.dirname(__filename);
52
+ const templatePath = path.join(__dirname, 'templates', 'api.mustache');
53
+ const template = fs.readFileSync(templatePath, 'utf-8');
54
+ let importDirectory = this._commandLineArgs.outputDirectory;
55
+ if (importDirectory.startsWith('lib/')) {
56
+ importDirectory = importDirectory.slice('lib/'.length);
57
+ }
58
+
59
+ const grouped = this._groupByTag(apis);
60
+
61
+ for (const [tag, apis] of Object.entries(grouped)) {
62
+ console.log(`Api: ${tag}`);
63
+
64
+ let subPath = '';
65
+ let filename = '';
66
+ let apiClassName = '';
67
+
68
+ subPath = Utils.toDartFileName(tag);
69
+ filename = `${Utils.toDartFileName(tag + 'Api')}`;
70
+ apiClassName = `${Utils.toDartClassName(tag + 'Api')}`;
71
+
72
+ var apiDefinition = <ApiDefinitionDart>{
73
+ package: this._commandLineArgs.package,
74
+ outputDirectory: this._commandLineArgs.outputDirectory,
75
+ filename: filename,
76
+ apiClassName: apiClassName,
77
+ }
78
+
79
+ var endpoints = <EndpointDefinitionDart[]>[];
80
+ var imports = <ImportDefinitionDart[]>[];
81
+
82
+ for (const api of apis) {
83
+ var requestType: string | undefined = undefined;
84
+ requestType = api.haveRequest ? api.parameters[0]?.typeName || 'void' : undefined;
85
+ requestType = requestType?.split('.').pop()!
86
+ requestType = Utils.toDartClassName(requestType);
87
+
88
+ var responseType: string = 'void';
89
+ responseType = api.returnType ? api.returnType.typeName : 'void';
90
+ responseType = responseType?.split('.').pop()!;
91
+ responseType = Utils.toDartClassName(responseType) ?? responseType;
92
+
93
+ var methodName = Utils.getNormalizedApiPath(api.name);
94
+ if (methodName.startsWith(Utils.toFirstLetterLowercase(tag))) {
95
+ methodName = methodName.slice(tag.length);
96
+ methodName = Utils.toFirstLetterLowercase(methodName);
97
+ }
98
+
99
+ // console.debug(`\tAPI - ${apiName} - ${apiMethod}`);
100
+ if (methodName == "userGeneralInfoTestSave") {
101
+ debugger
102
+ }
103
+
104
+ const endpoint = <EndpointDefinitionDart>{
105
+ methodName: methodName,
106
+ httpMethod: api.method.toLowerCase() as HttpMethodDart,
107
+ path: api.url,
108
+ responseType: responseType,
109
+ haveRequest: api.haveRequest,
110
+ requestType: requestType,
111
+ };
112
+
113
+ if (api.parameters && api.parameters.length > 0 && !api.haveRequest) {
114
+ endpoint.queryParams = api.parameters
115
+ .map(p => ({
116
+ name: p.name,
117
+ type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName)! : 'String',
118
+ nullable: p.nullable
119
+ }));
120
+ }
121
+
122
+ if (api.haveRequest && api.parameters[0]?.typeName) {
123
+ if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
124
+ models.forEach(model => {
125
+ if (model.typeName === api.parameters[0]?.typeName) {
126
+ const normalizedInfo = Normalizator.getNormalizedInfo(model);
127
+ imports.push({
128
+ type: api.parameters[0],
129
+ import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
130
+ });
131
+ }
132
+ });
133
+ }
134
+ }
135
+
136
+ if (api.returnType && !api.returnType.isNativeType) {
137
+ if (imports.findIndex(x => x.type.typeName == api.returnType!.typeName) == -1) {
138
+ models.forEach(model => {
139
+ if (model.typeName === api.returnType!.typeName) {
140
+ const normalizedInfo = Normalizator.getNormalizedInfo(model);
141
+ imports.push({
142
+ type: api.returnType!,
143
+ import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
144
+ });
145
+ }
146
+ });
147
+ }
148
+ }
149
+
150
+ endpoints.push(endpoint);
151
+ }
152
+
153
+ apiDefinition.endpoints = endpoints;
154
+ apiDefinition.imports = imports.map(i => i.import);
155
+
156
+ let destinationPath = `${this._commandLineArgs.outputDirectory}/${subPath}/api`;
157
+
158
+ Utils.ensureDirectorySync(`${destinationPath}`);
159
+
160
+ var result = Mustache.default.render(template, apiDefinition);
161
+ writeFileSync(`${destinationPath}/${apiDefinition.filename}.dart`, result, 'utf-8');
162
+ }
163
+ }
164
+
165
+ private _toPascalCase(input: string): string {
166
+ return input
167
+ .replace(/[_\- ]+/g, ' ') // sostituisce underscore, dash e spazi con uno spazio singolo
168
+ .trim() // rimuove spazi iniziali/finali
169
+ .split(' ') // divide in parole
170
+ .map(word =>
171
+ word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
172
+ )
173
+ .join('');
174
+ }
175
+
176
+ private _normalizeApiClassName(input: string): string {
177
+ return input
178
+ .replace(/\./g, '');
179
+ }
180
+
181
+ private _groupByTag(apis: ApiDto[]) {
182
+ const groupedByRole = apis.reduce<Record<string, ApiDto[]>>((acc, api) => {
183
+ if (!acc[api.tag]) {
184
+ acc[api.tag] = [];
185
+ }
186
+ acc[api.tag].push(api);
187
+ return acc;
188
+ }, {});
189
+ return groupedByRole;
190
+ }
186
191
  }