@devlearning/swagger-generator 1.0.25 → 1.0.27
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/.vscode/launch.json +28 -22
- package/README.md +209 -209
- package/dist/api.constants.js +22 -22
- package/dist/generators-writers/angular/api-angular-writer.js +15 -15
- package/dist/generators-writers/angular/constants.js +24 -24
- package/dist/generators-writers/angular/model-angular-writer.js +6 -6
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +12 -12
- package/dist/generators-writers/nextjs/constants.js +4 -4
- package/dist/generators-writers/nextjs/model-nextjs-writer.js +6 -6
- package/dist/models/swagger-component-property.js +1 -0
- package/dist/models/swagger-component.js +1 -0
- package/dist/models/swagger-content.js +1 -0
- package/dist/models/swagger-info.js +1 -0
- package/dist/models/swagger-method.js +1 -0
- package/dist/models/swagger-schema.js +1 -0
- package/dist/models/swagger.js +1 -0
- package/package.json +45 -45
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +582 -582
- package/src/generators-writers/angular/api-angular-writer.ts +141 -141
- package/src/generators-writers/angular/constants.ts +36 -36
- package/src/generators-writers/angular/model-angular-writer.ts +62 -62
- package/src/generators-writers/dart/api-dart-writer.ts +190 -190
- package/src/generators-writers/dart/model-dart-writer.ts +162 -162
- package/src/generators-writers/dart/models/import-definition-dart.ts +5 -5
- package/src/generators-writers/dart/normalizator.ts +72 -72
- package/src/generators-writers/dart/templates/api.mustache +36 -36
- package/src/generators-writers/dart/templates/enum.mustache +14 -13
- package/src/generators-writers/dart/templates/model.mustache +17 -17
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +156 -156
- package/src/generators-writers/nextjs/constants.ts +5 -5
- package/src/generators-writers/nextjs/model-nextjs-writer.ts +61 -61
- package/src/generators-writers/utils.ts +78 -78
- package/src/index.ts +96 -96
- package/src/models/api-dto.ts +17 -17
- package/src/models/enum-value-dto.ts +3 -3
- package/src/models/model-dto.ts +9 -9
- package/src/models/parameter-dto.ts +7 -7
- package/src/models/property-dto.ts +4 -4
- package/src/models/swagger/swagger-component-property.ts +11 -11
- package/src/models/swagger/swagger-component.ts +17 -17
- package/src/models/swagger/swagger-content.ts +4 -4
- package/src/models/swagger/swagger-info.ts +3 -3
- package/src/models/swagger/swagger-method.ts +7 -7
- package/src/models/swagger/swagger-schema.ts +20 -20
- package/src/models/swagger/swagger.ts +38 -38
- package/src/models/type-dto.ts +7 -7
- package/src/swagger-downloader.ts +12 -12
- package/tsconfig.json +28 -28
- package/autogen/identity/api/identity_api.dart +0 -100
- package/autogen/identity/models/auth_activate_command.dart +0 -14
- package/autogen/identity/models/auth_app_authenticate_command.dart +0 -16
- package/autogen/identity/models/auth_generate_reset_password_code_command.dart +0 -15
- package/autogen/identity/models/auth_refresh_token_command.dart +0 -15
- package/autogen/identity/models/auth_reset_password_command.dart +0 -16
- package/autogen/identity/models/auth_user_authenticate_command.dart +0 -15
- package/autogen/identity/models/auth_user_dto.dart +0 -18
- package/autogen/identity/models/auth_verify_reset_password_code_command.dart +0 -14
- package/autogen/identity/models/authentication_token.dart +0 -17
- package/autogen/mvc/models/problem_details.dart +0 -17
- package/autogen/product/api/product_api.dart +0 -70
- package/autogen/product/models/geoposition.dart +0 -14
- package/autogen/product/models/product_category_dto.dart +0 -15
- package/autogen/product/models/product_category_list_query_response.dart +0 -14
- package/autogen/product/models/product_category_save_command.dart +0 -15
- package/autogen/product/models/product_list_nearby_query.dart +0 -20
- package/autogen/product/models/product_list_nearby_query_filter.dart +0 -15
- package/autogen/product/models/product_list_nearby_query_order_by.dart +0 -10
- package/autogen/product/models/product_save_command.dart +0 -13
- package/autogen/service_defaults/models/application_exception.dart +0 -14
- package/autogen/service_defaults/models/result.dart +0 -17
- package/autogen/service_defaults/models/sort_direction.dart +0 -10
- package/autogen/user_profile/api/user_profile_api.dart +0 -51
- package/autogen/user_profile/models/user_general_info_save_command.dart +0 -17
- package/dist/generators-writers/dart/templates/api.mustache +0 -36
- package/dist/generators-writers/dart/templates/enum.mustache +0 -14
- package/dist/generators-writers/dart/templates/model.mustache +0 -18
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { API_POST, API_PRE } from './constants.js';
|
|
3
|
-
import { ApiDto } from '@src/models/api-dto.js';
|
|
4
|
-
import { Utils } from '../utils.js';
|
|
5
|
-
import { ParameterDto } from '@src/models/parameter-dto.js';
|
|
6
|
-
|
|
7
|
-
export class ApiAngularWriter {
|
|
8
|
-
private _outputDirectory: string;
|
|
9
|
-
|
|
10
|
-
constructor(_outputDirectory: string) {
|
|
11
|
-
this._outputDirectory = _outputDirectory;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
write(apis: ApiDto[]) {
|
|
15
|
-
let apiString = '';
|
|
16
|
-
|
|
17
|
-
apis.forEach(api => {
|
|
18
|
-
apiString += this._apiString(api);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this._writeFile(apiString);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private _apiString(api: ApiDto) {
|
|
26
|
-
|
|
27
|
-
let apiNameNormalized = Utils.getNormalizedApiPath(api.name);
|
|
28
|
-
let parametersString = this._parameters(api);
|
|
29
|
-
let queryParametersPreparation = this._queryParametersPreparation(api);
|
|
30
|
-
let requestPreparation = this._requestPreparation(api);
|
|
31
|
-
let queryParameters = this._queryParameters(api);
|
|
32
|
-
let returnTypeString = this._returnType(api);
|
|
33
|
-
let haveRequest = api.haveRequest;
|
|
34
|
-
let method = api.method.toLowerCase();
|
|
35
|
-
let httpOptions = api.isMultiPart ? 'httpOptionsMultiPart' : 'httpOptions';
|
|
36
|
-
|
|
37
|
-
let apiString = `
|
|
38
|
-
public ${apiNameNormalized}(${parametersString}): Observable<${returnTypeString}> {
|
|
39
|
-
${queryParametersPreparation}${requestPreparation}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${api.url}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
40
|
-
.pipe(
|
|
41
|
-
map(x => this._handleResponse(x)),
|
|
42
|
-
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
`;
|
|
46
|
-
|
|
47
|
-
return apiString;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private _parameters(api: ApiDto) {
|
|
51
|
-
let parametersString = '';
|
|
52
|
-
|
|
53
|
-
api.parameters.forEach(parameter => {
|
|
54
|
-
const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
|
|
55
|
-
parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${prefixType}${parameter.typeName}, `;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (api.parameters.length > 0)
|
|
59
|
-
parametersString = parametersString.substring(0, parametersString.length - 2);
|
|
60
|
-
|
|
61
|
-
return parametersString;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private _returnType(api: ApiDto) {
|
|
65
|
-
const prefixType = !api.returnType?.isNativeType ? 'Models.' : '';
|
|
66
|
-
const isArray = api.returnType?.isArray ? '[]' : '';
|
|
67
|
-
return api.returnType ? `${prefixType}${api.returnType.typeName}${isArray}` : 'any';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private _queryParametersPreparation(api: ApiDto) {
|
|
71
|
-
let queryParametersPreparation = '';
|
|
72
|
-
|
|
73
|
-
api.parameters.forEach(parameter => {
|
|
74
|
-
if (parameter.isQuery) {
|
|
75
|
-
queryParametersPreparation += this._queryParametersPreparationStatement(parameter);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return queryParametersPreparation
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private _queryParametersPreparationStatement(parameter: ParameterDto) {
|
|
83
|
-
if (parameter.nullable) {
|
|
84
|
-
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
85
|
-
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined && ${parameter.name}.isValid() ? encodeURIComponent(this._momentToString(${parameter.name})) : '';
|
|
86
|
-
`;
|
|
87
|
-
} else {
|
|
88
|
-
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
89
|
-
`;
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
93
|
-
return `let ${parameter.name}Param: string = encodeURIComponent(this._momentToString(${parameter.name}));
|
|
94
|
-
`;
|
|
95
|
-
} else {
|
|
96
|
-
return `let ${parameter.name}Param: string = encodeURIComponent('' + ${parameter.name});
|
|
97
|
-
`;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private _queryParameters(api: ApiDto) {
|
|
103
|
-
let queryParameters = '';
|
|
104
|
-
|
|
105
|
-
api.parameters.forEach(parameter => {
|
|
106
|
-
if (parameter.isQuery) {
|
|
107
|
-
queryParameters += this._queryParametersStatement(parameter);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (queryParameters.length > 0) {
|
|
112
|
-
queryParameters = '?' + queryParameters.substring(0, queryParameters.length - 1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return queryParameters;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private _queryParametersStatement(parameter: ParameterDto) {
|
|
119
|
-
if (parameter.swaggerParameter == null) return '';
|
|
120
|
-
|
|
121
|
-
if (!parameter.isQuery) return '';
|
|
122
|
-
|
|
123
|
-
return `${parameter.name}=\${${parameter.name}Param}&`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private _requestPreparation(api: ApiDto) {
|
|
127
|
-
if (!api.haveRequest) {
|
|
128
|
-
return '';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return `let wrappedRequest = this._handleRequest(request);
|
|
132
|
-
`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private _writeFile(apis: string) {
|
|
136
|
-
fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
|
|
137
|
-
`${API_PRE}
|
|
138
|
-
${apis}
|
|
139
|
-
${API_POST}`,
|
|
140
|
-
{ flag: 'w' });
|
|
141
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { API_POST, API_PRE } from './constants.js';
|
|
3
|
+
import { ApiDto } from '@src/models/api-dto.js';
|
|
4
|
+
import { Utils } from '../utils.js';
|
|
5
|
+
import { ParameterDto } from '@src/models/parameter-dto.js';
|
|
6
|
+
|
|
7
|
+
export class ApiAngularWriter {
|
|
8
|
+
private _outputDirectory: string;
|
|
9
|
+
|
|
10
|
+
constructor(_outputDirectory: string) {
|
|
11
|
+
this._outputDirectory = _outputDirectory;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
write(apis: ApiDto[]) {
|
|
15
|
+
let apiString = '';
|
|
16
|
+
|
|
17
|
+
apis.forEach(api => {
|
|
18
|
+
apiString += this._apiString(api);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
this._writeFile(apiString);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private _apiString(api: ApiDto) {
|
|
26
|
+
|
|
27
|
+
let apiNameNormalized = Utils.getNormalizedApiPath(api.name);
|
|
28
|
+
let parametersString = this._parameters(api);
|
|
29
|
+
let queryParametersPreparation = this._queryParametersPreparation(api);
|
|
30
|
+
let requestPreparation = this._requestPreparation(api);
|
|
31
|
+
let queryParameters = this._queryParameters(api);
|
|
32
|
+
let returnTypeString = this._returnType(api);
|
|
33
|
+
let haveRequest = api.haveRequest;
|
|
34
|
+
let method = api.method.toLowerCase();
|
|
35
|
+
let httpOptions = api.isMultiPart ? 'httpOptionsMultiPart' : 'httpOptions';
|
|
36
|
+
|
|
37
|
+
let apiString = `
|
|
38
|
+
public ${apiNameNormalized}(${parametersString}): Observable<${returnTypeString}> {
|
|
39
|
+
${queryParametersPreparation}${requestPreparation}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${api.url}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
40
|
+
.pipe(
|
|
41
|
+
map(x => this._handleResponse(x)),
|
|
42
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
return apiString;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private _parameters(api: ApiDto) {
|
|
51
|
+
let parametersString = '';
|
|
52
|
+
|
|
53
|
+
api.parameters.forEach(parameter => {
|
|
54
|
+
const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
|
|
55
|
+
parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${prefixType}${parameter.typeName}, `;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (api.parameters.length > 0)
|
|
59
|
+
parametersString = parametersString.substring(0, parametersString.length - 2);
|
|
60
|
+
|
|
61
|
+
return parametersString;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private _returnType(api: ApiDto) {
|
|
65
|
+
const prefixType = !api.returnType?.isNativeType ? 'Models.' : '';
|
|
66
|
+
const isArray = api.returnType?.isArray ? '[]' : '';
|
|
67
|
+
return api.returnType ? `${prefixType}${api.returnType.typeName}${isArray}` : 'any';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private _queryParametersPreparation(api: ApiDto) {
|
|
71
|
+
let queryParametersPreparation = '';
|
|
72
|
+
|
|
73
|
+
api.parameters.forEach(parameter => {
|
|
74
|
+
if (parameter.isQuery) {
|
|
75
|
+
queryParametersPreparation += this._queryParametersPreparationStatement(parameter);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return queryParametersPreparation
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _queryParametersPreparationStatement(parameter: ParameterDto) {
|
|
83
|
+
if (parameter.nullable) {
|
|
84
|
+
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
85
|
+
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined && ${parameter.name}.isValid() ? encodeURIComponent(this._momentToString(${parameter.name})) : '';
|
|
86
|
+
`;
|
|
87
|
+
} else {
|
|
88
|
+
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
93
|
+
return `let ${parameter.name}Param: string = encodeURIComponent(this._momentToString(${parameter.name}));
|
|
94
|
+
`;
|
|
95
|
+
} else {
|
|
96
|
+
return `let ${parameter.name}Param: string = encodeURIComponent('' + ${parameter.name});
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private _queryParameters(api: ApiDto) {
|
|
103
|
+
let queryParameters = '';
|
|
104
|
+
|
|
105
|
+
api.parameters.forEach(parameter => {
|
|
106
|
+
if (parameter.isQuery) {
|
|
107
|
+
queryParameters += this._queryParametersStatement(parameter);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (queryParameters.length > 0) {
|
|
112
|
+
queryParameters = '?' + queryParameters.substring(0, queryParameters.length - 1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return queryParameters;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private _queryParametersStatement(parameter: ParameterDto) {
|
|
119
|
+
if (parameter.swaggerParameter == null) return '';
|
|
120
|
+
|
|
121
|
+
if (!parameter.isQuery) return '';
|
|
122
|
+
|
|
123
|
+
return `${parameter.name}=\${${parameter.name}Param}&`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private _requestPreparation(api: ApiDto) {
|
|
127
|
+
if (!api.haveRequest) {
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return `let wrappedRequest = this._handleRequest(request);
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private _writeFile(apis: string) {
|
|
136
|
+
fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
|
|
137
|
+
`${API_PRE}
|
|
138
|
+
${apis}
|
|
139
|
+
${API_POST}`,
|
|
140
|
+
{ flag: 'w' });
|
|
141
|
+
}
|
|
142
142
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export const API_PRE =
|
|
2
|
-
`import { HttpClient } from '@angular/common/http';
|
|
3
|
-
import { Observable, catchError, map } from 'rxjs';
|
|
4
|
-
import * as Models from './model.autogenerated';
|
|
5
|
-
import { HttpHeaders } from "@angular/common/http";
|
|
6
|
-
|
|
7
|
-
export const httpOptions = {
|
|
8
|
-
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const httpOptionsMultipart = {};
|
|
12
|
-
|
|
13
|
-
export abstract class ApiAutogeneratedService {
|
|
14
|
-
constructor(
|
|
15
|
-
public _http: HttpClient,
|
|
16
|
-
public _baseUrl: string,
|
|
17
|
-
) { }
|
|
18
|
-
|
|
19
|
-
protected abstract _momentToString(moment: moment.Moment): string;
|
|
20
|
-
protected abstract _handleRequest<T>(request: T): T;
|
|
21
|
-
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
22
|
-
protected abstract _handleResponse<T>(response: T): T;
|
|
23
|
-
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
export const API_POST =
|
|
27
|
-
`}`;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const MODEL_PRE =
|
|
31
|
-
`import * as moment from 'moment';
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
export const MODEL_POST =
|
|
35
|
-
`
|
|
36
|
-
`;
|
|
1
|
+
export const API_PRE =
|
|
2
|
+
`import { HttpClient } from '@angular/common/http';
|
|
3
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
4
|
+
import * as Models from './model.autogenerated';
|
|
5
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
6
|
+
|
|
7
|
+
export const httpOptions = {
|
|
8
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const httpOptionsMultipart = {};
|
|
12
|
+
|
|
13
|
+
export abstract class ApiAutogeneratedService {
|
|
14
|
+
constructor(
|
|
15
|
+
public _http: HttpClient,
|
|
16
|
+
public _baseUrl: string,
|
|
17
|
+
) { }
|
|
18
|
+
|
|
19
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
20
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
21
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
22
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
23
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const API_POST =
|
|
27
|
+
`}`;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export const MODEL_PRE =
|
|
31
|
+
`import * as moment from 'moment';
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const MODEL_POST =
|
|
35
|
+
`
|
|
36
|
+
`;
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { MODEL_POST, MODEL_PRE } from './constants.js';
|
|
3
|
-
import { ModelDto } from '@src/models/model-dto.js';
|
|
4
|
-
|
|
5
|
-
export class ModelAngularWriter {
|
|
6
|
-
private _outputDirectory: string;
|
|
7
|
-
|
|
8
|
-
constructor(_outputDirectory: string) {
|
|
9
|
-
this._outputDirectory = _outputDirectory;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
write(models: ModelDto[]) {
|
|
13
|
-
let modelString = '';
|
|
14
|
-
|
|
15
|
-
models.forEach(model => {
|
|
16
|
-
modelString += this._modelString(model);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this._writeFile(modelString);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private _modelString(model: ModelDto) {
|
|
24
|
-
let modelString = `
|
|
25
|
-
export ${model.modelType} ${model.name} {
|
|
26
|
-
${this._properties(model)}${this._enumValues(model)}
|
|
27
|
-
}
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
|
-
return modelString;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private _properties(model: ModelDto) {
|
|
34
|
-
let propertiesString = '';
|
|
35
|
-
|
|
36
|
-
model.properties.forEach(property => {
|
|
37
|
-
//const libraryDate = this._commandLineArgs.dateTimeLibrary == DateTimeLibrary.Moment ? 'moment.Moment' : 'Date'
|
|
38
|
-
const libraryDate = 'moment.Moment';
|
|
39
|
-
const typeName = property.typeName === 'dateTime' ? libraryDate : property.typeName;
|
|
40
|
-
propertiesString += ` ${property.name}${property.nullable ? '?' : ''}: ${typeName};\n`;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return propertiesString.trimEnd();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private _enumValues(model: ModelDto) {
|
|
47
|
-
let enumValuesString = '';
|
|
48
|
-
|
|
49
|
-
model.enumValues.forEach(enumValue => {
|
|
50
|
-
enumValuesString += ` ${enumValue.name} = ${enumValue.value},\n`;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return enumValuesString.trimEnd();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private _writeFile(models: string) {
|
|
57
|
-
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
|
|
58
|
-
`${MODEL_PRE}
|
|
59
|
-
${models}
|
|
60
|
-
${MODEL_POST}`,
|
|
61
|
-
{ flag: 'w' });
|
|
62
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { MODEL_POST, MODEL_PRE } from './constants.js';
|
|
3
|
+
import { ModelDto } from '@src/models/model-dto.js';
|
|
4
|
+
|
|
5
|
+
export class ModelAngularWriter {
|
|
6
|
+
private _outputDirectory: string;
|
|
7
|
+
|
|
8
|
+
constructor(_outputDirectory: string) {
|
|
9
|
+
this._outputDirectory = _outputDirectory;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
write(models: ModelDto[]) {
|
|
13
|
+
let modelString = '';
|
|
14
|
+
|
|
15
|
+
models.forEach(model => {
|
|
16
|
+
modelString += this._modelString(model);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
this._writeFile(modelString);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private _modelString(model: ModelDto) {
|
|
24
|
+
let modelString = `
|
|
25
|
+
export ${model.modelType} ${model.name} {
|
|
26
|
+
${this._properties(model)}${this._enumValues(model)}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
return modelString;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _properties(model: ModelDto) {
|
|
34
|
+
let propertiesString = '';
|
|
35
|
+
|
|
36
|
+
model.properties.forEach(property => {
|
|
37
|
+
//const libraryDate = this._commandLineArgs.dateTimeLibrary == DateTimeLibrary.Moment ? 'moment.Moment' : 'Date'
|
|
38
|
+
const libraryDate = 'moment.Moment';
|
|
39
|
+
const typeName = property.typeName === 'dateTime' ? libraryDate : property.typeName;
|
|
40
|
+
propertiesString += ` ${property.name}${property.nullable ? '?' : ''}: ${typeName};\n`;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return propertiesString.trimEnd();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private _enumValues(model: ModelDto) {
|
|
47
|
+
let enumValuesString = '';
|
|
48
|
+
|
|
49
|
+
model.enumValues.forEach(enumValue => {
|
|
50
|
+
enumValuesString += ` ${enumValue.name} = ${enumValue.value},\n`;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return enumValuesString.trimEnd();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private _writeFile(models: string) {
|
|
57
|
+
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
|
|
58
|
+
`${MODEL_PRE}
|
|
59
|
+
${models}
|
|
60
|
+
${MODEL_POST}`,
|
|
61
|
+
{ flag: 'w' });
|
|
62
|
+
}
|
|
63
63
|
}
|