@devlearning/swagger-generator 1.0.9 → 1.0.11
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/autogeneration/output/api.autogenerated.ts +95 -0
- package/autogeneration/output/model.autogenerated.ts +69 -0
- package/dist/api.constants.js +24 -0
- package/dist/generator-old.js +369 -0
- package/dist/generator.js +483 -0
- package/dist/generators-writers/angular/api-angular-writer.js +114 -0
- package/dist/generators-writers/angular/constants.js +28 -0
- package/dist/generators-writers/angular/model-angular-writer.js +42 -0
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +127 -0
- package/dist/generators-writers/nextjs/constants.js +5 -0
- package/dist/generators-writers/nextjs/model-nextjs-writer.js +41 -0
- package/dist/generators-writers/utils.js +20 -0
- package/dist/index.js +24 -0
- package/dist/model.constants.js +1 -0
- package/dist/models/api-dto.js +1 -0
- package/dist/models/enum-value-dto.js +1 -0
- package/dist/models/model-dto.js +1 -0
- package/dist/models/parameter-dto.js +1 -0
- package/dist/models/property-dto.js +1 -0
- package/dist/models/swagger/swagger-component-property.js +1 -0
- package/dist/models/swagger/swagger-component.js +1 -0
- package/dist/models/swagger/swagger-content.js +1 -0
- package/dist/models/swagger/swagger-info.js +1 -0
- package/dist/models/swagger/swagger-method.js +1 -0
- package/dist/models/swagger/swagger-schema.js +1 -0
- package/dist/models/swagger/swagger.js +1 -0
- package/dist/models/type-dto.js +1 -0
- package/dist/swagger-downloader.js +9 -0
- package/package.json +1 -1
- package/src/generator.ts +170 -110
- package/src/generators-writers/angular/api-angular-writer.ts +2 -1
- package/src/models/swagger/swagger-component-property.ts +2 -0
- package/src/models/type-dto.ts +4 -1
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
+
import * as Models from './model.autogenerated';
|
|
4
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
+
|
|
6
|
+
export const httpOptions = {
|
|
7
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const httpOptionsMultipart = {};
|
|
11
|
+
|
|
12
|
+
export abstract class ApiAutogeneratedService {
|
|
13
|
+
constructor(
|
|
14
|
+
public _http: HttpClient,
|
|
15
|
+
public _baseUrl: string,
|
|
16
|
+
) { }
|
|
17
|
+
|
|
18
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
public catalog_Product_Read(idProduct?: number): Observable<Models.Product> {
|
|
26
|
+
let idProductParam: string = idProduct != null && idProduct != undefined ? encodeURIComponent('' + idProduct) : '';
|
|
27
|
+
return this._http.get<Models.Product>(`${this._baseUrl}/catalog/Product/Read?idProduct=${idProductParam}`, httpOptions)
|
|
28
|
+
.pipe(
|
|
29
|
+
map(x => this._handleResponse(x)),
|
|
30
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public catalog_Product_List(): Observable<Models.Product[]> {
|
|
35
|
+
return this._http.get<Models.Product[]>(`${this._baseUrl}/catalog/Product/List`, httpOptions)
|
|
36
|
+
.pipe(
|
|
37
|
+
map(x => this._handleResponse(x)),
|
|
38
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public identiy_token(request: Models.AuthTokenCommand): Observable<Models.AuthenticationToken> {
|
|
43
|
+
let wrappedRequest = this._handleRequest(request);
|
|
44
|
+
return this._http.post<Models.AuthenticationToken>(`${this._baseUrl}/identiy/token`, wrappedRequest, httpOptions)
|
|
45
|
+
.pipe(
|
|
46
|
+
map(x => this._handleResponse(x)),
|
|
47
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public identiy_refreshToken(request: Models.AuthRefreshTokenCommand): Observable<Models.AuthenticationToken> {
|
|
52
|
+
let wrappedRequest = this._handleRequest(request);
|
|
53
|
+
return this._http.post<Models.AuthenticationToken>(`${this._baseUrl}/identiy/refreshToken`, wrappedRequest, httpOptions)
|
|
54
|
+
.pipe(
|
|
55
|
+
map(x => this._handleResponse(x)),
|
|
56
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public identiy_generateResetPasswordCode(request: Models.AuthGenerateResetPasswordCodeCommand): Observable<Models.Result> {
|
|
61
|
+
let wrappedRequest = this._handleRequest(request);
|
|
62
|
+
return this._http.post<Models.Result>(`${this._baseUrl}/identiy/generateResetPasswordCode`, wrappedRequest, httpOptions)
|
|
63
|
+
.pipe(
|
|
64
|
+
map(x => this._handleResponse(x)),
|
|
65
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public identiy_resetPassword(request: Models.AuthResetPasswordCommand): Observable<Models.Result> {
|
|
70
|
+
let wrappedRequest = this._handleRequest(request);
|
|
71
|
+
return this._http.post<Models.Result>(`${this._baseUrl}/identiy/resetPassword`, wrappedRequest, httpOptions)
|
|
72
|
+
.pipe(
|
|
73
|
+
map(x => this._handleResponse(x)),
|
|
74
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public identiy_verifyResetPasswordCode(request: Models.AuthVerifyResetPasswordCodeCommand): Observable<Models.Result> {
|
|
79
|
+
let wrappedRequest = this._handleRequest(request);
|
|
80
|
+
return this._http.post<Models.Result>(`${this._baseUrl}/identiy/verifyResetPasswordCode`, wrappedRequest, httpOptions)
|
|
81
|
+
.pipe(
|
|
82
|
+
map(x => this._handleResponse(x)),
|
|
83
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public tenant_Tenant(): Observable<string> {
|
|
88
|
+
return this._http.get<string>(`${this._baseUrl}/tenant/Tenant`, httpOptions)
|
|
89
|
+
.pipe(
|
|
90
|
+
map(x => this._handleResponse(x)),
|
|
91
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as moment from 'moment';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export class ApplicationException {
|
|
5
|
+
message?: string;
|
|
6
|
+
stackTrace?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AuthGenerateResetPasswordCodeCommand {
|
|
10
|
+
usernameOrEmail?: string;
|
|
11
|
+
host?: string;
|
|
12
|
+
urlResetPassword?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class AuthRefreshTokenCommand {
|
|
16
|
+
username: string;
|
|
17
|
+
refreshToken: string;
|
|
18
|
+
ipAddress?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class AuthResetPasswordCommand {
|
|
22
|
+
usernameOrEmail: string;
|
|
23
|
+
verificationCode: string;
|
|
24
|
+
password: string;
|
|
25
|
+
confirmPassword: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class AuthTokenCommand {
|
|
29
|
+
username: string;
|
|
30
|
+
password: string;
|
|
31
|
+
ipAddress?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class AuthVerifyResetPasswordCodeCommand {
|
|
35
|
+
usernameOrEmail?: string;
|
|
36
|
+
verificationCode?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class AuthenticationToken {
|
|
40
|
+
idAuthUser: string;
|
|
41
|
+
username?: string;
|
|
42
|
+
accessToken?: string;
|
|
43
|
+
expiresIn: number;
|
|
44
|
+
refreshToken?: string;
|
|
45
|
+
refreshTokenExpiresIn: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class ProblemDetails {
|
|
49
|
+
type?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
status?: number;
|
|
52
|
+
detail?: string;
|
|
53
|
+
instance?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class Product {
|
|
57
|
+
idProduct: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
quantity: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class Result {
|
|
63
|
+
isSuccess: boolean;
|
|
64
|
+
message?: string;
|
|
65
|
+
stacktrace?: string;
|
|
66
|
+
exception: ApplicationException;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
+
import * as Models from './model.autogenerated';
|
|
4
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
+
|
|
6
|
+
export const httpOptions = {
|
|
7
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const httpOptionsMultipart = {};
|
|
11
|
+
|
|
12
|
+
export abstract class ApiAutogeneratedService {
|
|
13
|
+
constructor(
|
|
14
|
+
public _http: HttpClient,
|
|
15
|
+
public _baseUrl: string,
|
|
16
|
+
) { }
|
|
17
|
+
|
|
18
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
23
|
+
`;
|
|
24
|
+
export const API_POST = `}`;
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// import fs from 'fs';
|
|
2
|
+
// import { SwaggerComponent } from './models/swagger/swagger-component.js';
|
|
3
|
+
// import { Swagger, SwaggerParameter } from './models/swagger/swagger.js';
|
|
4
|
+
// import { SwaggerMethod } from './models/swagger/swagger-method.js';
|
|
5
|
+
// import { SwaggerComponentProperty } from './models/swagger/swagger-component-property.js';
|
|
6
|
+
// import { SwaggerSchema } from './models/swagger/swagger-schema.js';
|
|
7
|
+
// import { API_PRE, API_POST } from './api.constants.js';
|
|
8
|
+
// import { MODEL_POST, MODEL_PRE } from './model.constants.js';
|
|
9
|
+
export {};
|
|
10
|
+
// const contentTypeApplicationJson = 'application/json';
|
|
11
|
+
// const contentTypeMultipartFormData = 'multipart/form-data';
|
|
12
|
+
// export class GeneratorOld {
|
|
13
|
+
// private _swagger: Swagger;
|
|
14
|
+
// private _outputDirectory: string;
|
|
15
|
+
// private _outputFormat: 'angular' | 'next';
|
|
16
|
+
// constructor(swagger: Swagger, outputDirectory: string, outputFormat: 'angular' | 'next') {
|
|
17
|
+
// this._swagger = swagger;
|
|
18
|
+
// this._outputDirectory = outputDirectory;
|
|
19
|
+
// this._outputFormat = outputFormat
|
|
20
|
+
// }
|
|
21
|
+
// generateApi() {
|
|
22
|
+
// console.debug(`Start autogeneration Apis`);
|
|
23
|
+
// let apiMethods = ``;
|
|
24
|
+
// for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
|
|
25
|
+
// const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
|
|
26
|
+
// const swaggerMethod = this._swagger.paths[apiName];
|
|
27
|
+
// const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
28
|
+
// const swaggerMethodInfo = swaggerMethod[method];
|
|
29
|
+
// console.debug(`\tAPI - ${apiName} - ${method}`);
|
|
30
|
+
// let parametersString = this.retrieveParameters(swaggerMethodInfo, apiName);
|
|
31
|
+
// let queryParametersDeclaration = this.retrieveQueryParametersDeclaration(swaggerMethodInfo);
|
|
32
|
+
// let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
|
|
33
|
+
// let returnTypeString = this.retrieveReturnType(swaggerMethodInfo);
|
|
34
|
+
// if (returnTypeString == null) returnTypeString = 'void';
|
|
35
|
+
// let prepareRequestString = ``; //request = this._handleRequest(request);
|
|
36
|
+
// let haveRequest = swaggerMethodInfo.requestBody != null;
|
|
37
|
+
// let isMultiPart = haveRequest && swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData] != null;
|
|
38
|
+
// let httpOptions = 'httpOptions';
|
|
39
|
+
// if (haveRequest && !isMultiPart) {
|
|
40
|
+
// prepareRequestString = `const wrappedRequest = this._handleRequest(request);
|
|
41
|
+
// `;
|
|
42
|
+
// } else if (isMultiPart) {
|
|
43
|
+
// prepareRequestString = `const wrappedRequest = this._handleMultipart(request);
|
|
44
|
+
// `;
|
|
45
|
+
// httpOptions = `httpOptionsMultipart`;
|
|
46
|
+
// }
|
|
47
|
+
// apiMethods +=
|
|
48
|
+
// `
|
|
49
|
+
// public ${this.getApiNameNormalized(apiName)}(${parametersString}): Observable<${returnTypeString}> {
|
|
50
|
+
// ${queryParametersDeclaration}${prepareRequestString}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${apiName.replace('{version}', '1')}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
51
|
+
// .pipe(
|
|
52
|
+
// map(x => this._handleResponse(x)),
|
|
53
|
+
// catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
54
|
+
// );
|
|
55
|
+
// }
|
|
56
|
+
// `;
|
|
57
|
+
// }
|
|
58
|
+
// fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
|
|
59
|
+
// `${API_PRE}
|
|
60
|
+
// ${apiMethods}
|
|
61
|
+
// ${API_POST}`,
|
|
62
|
+
// { flag: 'w' });
|
|
63
|
+
// }
|
|
64
|
+
// generateModel() {
|
|
65
|
+
// let usedTypes: string[] = [];
|
|
66
|
+
// let usedMultiPart: string[] = [];
|
|
67
|
+
// for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
|
|
68
|
+
// const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
|
|
69
|
+
// const swaggerMethod = this._swagger.paths[apiName];
|
|
70
|
+
// const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
71
|
+
// const swaggerMethodInfo = swaggerMethod[method];
|
|
72
|
+
// if (apiName == "/api/v{version}/TicketFile/Create") {
|
|
73
|
+
// debugger
|
|
74
|
+
// }
|
|
75
|
+
// let parametersRefType = swaggerMethodInfo.parameters?.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''))
|
|
76
|
+
// if (parametersRefType) {
|
|
77
|
+
// usedTypes = usedTypes.concat(parametersRefType);
|
|
78
|
+
// if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
|
|
79
|
+
// usedTypes.push(swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
|
|
80
|
+
// }
|
|
81
|
+
// if (swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref) {
|
|
82
|
+
// usedTypes.push(swaggerMethodInfo.requestBody?.content[contentTypeApplicationJson]?.schema?.$ref.replace('#/components/schemas/', ''));
|
|
83
|
+
// }
|
|
84
|
+
// if (swaggerMethodInfo.requestBody?.content[contentTypeMultipartFormData]?.schema != null) {
|
|
85
|
+
// usedMultiPart.push(apiName);
|
|
86
|
+
// }
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// this.retrieveNestedObjects(usedTypes);
|
|
90
|
+
// usedTypes = [...new Set(usedTypes.map(item => item))]; // [ 'A', 'B']
|
|
91
|
+
// // usedTypes = usedTypes.filter((value, index, array) => {
|
|
92
|
+
// // array.indexOf(value) === index;
|
|
93
|
+
// // });
|
|
94
|
+
// // usedTypes.forEach(element => {
|
|
95
|
+
// // console.debug(element);
|
|
96
|
+
// // });
|
|
97
|
+
// console.debug(`Start autogeneration Models`);
|
|
98
|
+
// let models = ``;
|
|
99
|
+
// if (this._swagger.components != null
|
|
100
|
+
// && this._swagger.components != undefined
|
|
101
|
+
// && this._swagger.components.schemas != null
|
|
102
|
+
// && this._swagger.components.schemas != undefined) {
|
|
103
|
+
// for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.components.schemas).length; index++) {
|
|
104
|
+
// const modelName = Object.getOwnPropertyNames(this._swagger.components.schemas)[index];
|
|
105
|
+
// if (modelName == 'ActivatedVoucherSnackListResponse') {
|
|
106
|
+
// console.debug("ActivatedVoucherSnackListResponse");
|
|
107
|
+
// }
|
|
108
|
+
// if (usedTypes.indexOf(modelName) < 0) {
|
|
109
|
+
// console.debug(`\tModel SKIP - ${modelName}`);
|
|
110
|
+
// continue
|
|
111
|
+
// };
|
|
112
|
+
// const swaggerCopmponent = this._swagger.components.schemas[modelName];
|
|
113
|
+
// console.debug(`\tModel - ${modelName}`);
|
|
114
|
+
// let type = swaggerCopmponent.type == 'integer' ? 'enum' : 'class';
|
|
115
|
+
// let content = this.retrieveObjectContent(modelName, swaggerCopmponent);
|
|
116
|
+
// models +=
|
|
117
|
+
// `
|
|
118
|
+
// export ${type} ${modelName} {${content}
|
|
119
|
+
// }
|
|
120
|
+
// `;
|
|
121
|
+
// }
|
|
122
|
+
// }
|
|
123
|
+
// usedMultiPart.forEach(apiName => {
|
|
124
|
+
// const swaggerMethod = this._swagger.paths[apiName];
|
|
125
|
+
// const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
126
|
+
// const swaggerMethodInfo = swaggerMethod[method];
|
|
127
|
+
// let type = 'class';
|
|
128
|
+
// let modelName = this.getApiNameNormalized(apiName);
|
|
129
|
+
// let content = this.retrieveSchemaProperties(swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData].schema);
|
|
130
|
+
// models +=
|
|
131
|
+
// `
|
|
132
|
+
// export ${type} ${modelName} {${content}
|
|
133
|
+
// }
|
|
134
|
+
// `;
|
|
135
|
+
// });
|
|
136
|
+
// fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
|
|
137
|
+
// `${MODEL_PRE}
|
|
138
|
+
// ${models}
|
|
139
|
+
// ${MODEL_POST}`,
|
|
140
|
+
// { flag: 'w' });
|
|
141
|
+
// }
|
|
142
|
+
// retrieveParameters(swaggerMethodInfo: SwaggerMethod, apiName: string) {
|
|
143
|
+
// if (swaggerMethodInfo.requestBody != null && swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData] != null) {
|
|
144
|
+
// var modelName = this.getApiNameNormalized(apiName);
|
|
145
|
+
// return `request: Models.${modelName}`;
|
|
146
|
+
// } else {
|
|
147
|
+
// if (swaggerMethodInfo.requestBody != null) {
|
|
148
|
+
// return `request: Models.${swaggerMethodInfo.requestBody.content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', '')}`
|
|
149
|
+
// }
|
|
150
|
+
// let parameters = ``;
|
|
151
|
+
// swaggerMethodInfo.parameters?.filter(x => x.in == 'query').forEach(parameter => {
|
|
152
|
+
// if (parameter.schema.$ref != null) {
|
|
153
|
+
// parameters += `${this.toFirstLetterLowercase(parameter.name)}: Models.${parameter.schema.$ref.replace('#/components/schemas/', '')}, `;
|
|
154
|
+
// } else {
|
|
155
|
+
// const nativeType = this.getNativeType(parameter.schema);
|
|
156
|
+
// const nullable = !parameter.required ? '?' : '';
|
|
157
|
+
// parameters += `${this.toFirstLetterLowercase(parameter.name)}${nullable}: ${nativeType}, `;
|
|
158
|
+
// }
|
|
159
|
+
// });
|
|
160
|
+
// if (parameters.length > 2)
|
|
161
|
+
// parameters = parameters.substring(0, parameters.length - 2);
|
|
162
|
+
// return parameters;
|
|
163
|
+
// }
|
|
164
|
+
// }
|
|
165
|
+
// retrieveQueryParametersDeclaration(swaggerMethodInfo: SwaggerMethod) {
|
|
166
|
+
// if (swaggerMethodInfo.requestBody != null) return ``;
|
|
167
|
+
// let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
|
|
168
|
+
// if (filteredParameters == null || filteredParameters == undefined || filteredParameters.length == 0) return ``;
|
|
169
|
+
// let parameters = ``;
|
|
170
|
+
// filteredParameters.forEach(parameter => {
|
|
171
|
+
// if (parameter.schema.$ref != null) {
|
|
172
|
+
// if (this.isEnum(parameter.schema.$ref) != null) {
|
|
173
|
+
// parameters += this.retrieveQueryParametersDeclarationStatement(parameter);
|
|
174
|
+
// } else {
|
|
175
|
+
// throw new Error("retrieveQueryParameters unmanaged parameter.schema.$ref");
|
|
176
|
+
// }
|
|
177
|
+
// } else {
|
|
178
|
+
// parameters += this.retrieveQueryParametersDeclarationStatement(parameter);
|
|
179
|
+
// }
|
|
180
|
+
// });
|
|
181
|
+
// // if (parameters.length > 2)
|
|
182
|
+
// // parameters = parameters.substring(0, parameters.length - 1);
|
|
183
|
+
// return parameters;
|
|
184
|
+
// }
|
|
185
|
+
// retrieveQueryParametersDeclarationStatement(parameter: SwaggerParameter) {
|
|
186
|
+
// let paramName = this.toFirstLetterLowercase(parameter.name);
|
|
187
|
+
// if (!parameter.required) {
|
|
188
|
+
// if (this.isDate(parameter.schema)) {
|
|
189
|
+
// return `let ${paramName}Param: string = ${paramName} != null && ${paramName} != undefined && ${paramName}.isValid() ? encodeURIComponent(this._momentToString(${paramName})) : '';
|
|
190
|
+
// `;
|
|
191
|
+
// } else {
|
|
192
|
+
// return `let ${paramName}Param: string = ${paramName} != null && ${paramName} != undefined ? encodeURIComponent('' + ${paramName}) : '';
|
|
193
|
+
// `;
|
|
194
|
+
// }
|
|
195
|
+
// } else {
|
|
196
|
+
// if (this.isDate(parameter.schema)) {
|
|
197
|
+
// return `let ${paramName}Param: string = encodeURIComponent(this._momentToString(${paramName}));
|
|
198
|
+
// `;
|
|
199
|
+
// } else {
|
|
200
|
+
// return `let ${paramName}Param: string = encodeURIComponent('' + ${paramName});
|
|
201
|
+
// `;
|
|
202
|
+
// }
|
|
203
|
+
// }
|
|
204
|
+
// }
|
|
205
|
+
// retrieveQueryParameters(swaggerMethodInfo: SwaggerMethod) {
|
|
206
|
+
// if (swaggerMethodInfo.requestBody != null) return ``;
|
|
207
|
+
// let filteredParameters = swaggerMethodInfo.parameters?.filter(x => x.in == 'query');
|
|
208
|
+
// if (filteredParameters == null || filteredParameters == undefined || filteredParameters.length == 0) return ``;
|
|
209
|
+
// let parameters = `?`;
|
|
210
|
+
// filteredParameters.forEach(parameter => {
|
|
211
|
+
// if (parameter.schema.$ref != null) {
|
|
212
|
+
// if (this.isEnum(parameter.schema.$ref) != null) {
|
|
213
|
+
// parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `Param}&`;;
|
|
214
|
+
// } else {
|
|
215
|
+
// throw new Error("retrieveQueryParameters unmanaged parameter.schema.$ref");
|
|
216
|
+
// }
|
|
217
|
+
// } else {
|
|
218
|
+
// parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `Param}&`;
|
|
219
|
+
// }
|
|
220
|
+
// });
|
|
221
|
+
// if (parameters.length > 1)
|
|
222
|
+
// parameters = parameters.substring(0, parameters.length - 1);
|
|
223
|
+
// return parameters;
|
|
224
|
+
// }
|
|
225
|
+
// retrieveReturnType(swaggerMethodInfo: SwaggerMethod) {
|
|
226
|
+
// if (swaggerMethodInfo.responses[200] == null)
|
|
227
|
+
// return 'void';
|
|
228
|
+
// try {
|
|
229
|
+
// if (swaggerMethodInfo.responses[200].content[contentTypeApplicationJson].schema.$ref != null)
|
|
230
|
+
// return `Models.${this.getObjectName(swaggerMethodInfo.responses[200]?.content[contentTypeApplicationJson].schema.$ref)}`;
|
|
231
|
+
// } catch (error) {
|
|
232
|
+
// const errorMessage = "\t\tAttenzione forse hai dimenticato IActionResult e non hai tipizzato il tipo restituito dal servizio";
|
|
233
|
+
// console.error(`%c${errorMessage}`, 'color: red');
|
|
234
|
+
// throw new Error(errorMessage);
|
|
235
|
+
// }
|
|
236
|
+
// if (swaggerMethodInfo.responses[200]?.content[contentTypeApplicationJson].schema.type != null)
|
|
237
|
+
// return this.getNativeType(swaggerMethodInfo.responses[200]?.content[contentTypeApplicationJson].schema);
|
|
238
|
+
// console.error("unmanaged swaggerMethodInfo", swaggerMethodInfo);
|
|
239
|
+
// throw new Error("unmanaged swaggerMethodInfo");
|
|
240
|
+
// }
|
|
241
|
+
// retrieveType(swaggerComponentProperty: SwaggerComponentProperty) {
|
|
242
|
+
// if (swaggerComponentProperty.$ref != null)
|
|
243
|
+
// return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
|
|
244
|
+
// if (swaggerComponentProperty.type != null && swaggerComponentProperty.type == 'array')
|
|
245
|
+
// if (swaggerComponentProperty.items.$ref != null)
|
|
246
|
+
// return `${this.getObjectName(swaggerComponentProperty.items.$ref)}[]`;
|
|
247
|
+
// else
|
|
248
|
+
// return this.getNativeType(swaggerComponentProperty);
|
|
249
|
+
// if (swaggerComponentProperty.type != null)
|
|
250
|
+
// return this.getNativeType(swaggerComponentProperty);
|
|
251
|
+
// if (swaggerComponentProperty.type == null)
|
|
252
|
+
// return '';
|
|
253
|
+
// console.error("unmanaged swaggerMethodInfo", swaggerComponentProperty);
|
|
254
|
+
// throw new Error("unmanaged swaggerMethodInfo");
|
|
255
|
+
// }
|
|
256
|
+
// parametrizeObject(objectName: string) {
|
|
257
|
+
// let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
258
|
+
// if (component == null || component.properties == null) return ``;
|
|
259
|
+
// console.debug(component.properties);
|
|
260
|
+
// return ``;
|
|
261
|
+
// }
|
|
262
|
+
// isEnum(objectName: string) {
|
|
263
|
+
// let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
264
|
+
// return component.enum != null;
|
|
265
|
+
// }
|
|
266
|
+
// isDate(schema: SwaggerSchema) {
|
|
267
|
+
// return schema.type == 'string' && schema.format == 'date-time';
|
|
268
|
+
// }
|
|
269
|
+
// getObjectName(ref: string) {
|
|
270
|
+
// return ref.replace('#/components/schemas/', '');
|
|
271
|
+
// }
|
|
272
|
+
// retrieveObjectContent(name: string, swaggerComponent: SwaggerComponent) {
|
|
273
|
+
// if (swaggerComponent.type == 'object')
|
|
274
|
+
// return this.retrieveComponentProperties(swaggerComponent);
|
|
275
|
+
// else if (swaggerComponent.type == 'integer')
|
|
276
|
+
// return this.retrieveEnumValues(name, swaggerComponent);
|
|
277
|
+
// }
|
|
278
|
+
// retrieveComponentProperties(swaggerCopmponent: SwaggerComponent) {
|
|
279
|
+
// if (swaggerCopmponent.properties == null) return ``;
|
|
280
|
+
// let properties = ``;
|
|
281
|
+
// for (let index = 0; index < Object.getOwnPropertyNames(swaggerCopmponent.properties).length; index++) {
|
|
282
|
+
// const propertyName = Object.getOwnPropertyNames(swaggerCopmponent.properties)[index];
|
|
283
|
+
// properties +=
|
|
284
|
+
// `
|
|
285
|
+
// ${propertyName}: ${this.retrieveType(swaggerCopmponent.properties[propertyName])} | undefined;`
|
|
286
|
+
// }
|
|
287
|
+
// return properties;
|
|
288
|
+
// }
|
|
289
|
+
// retrieveSchemaProperties(schema: SwaggerSchema) {
|
|
290
|
+
// if (schema.properties == null) return ``;
|
|
291
|
+
// let properties = ``;
|
|
292
|
+
// for (let j = 0; j < Object.getOwnPropertyNames(schema.properties).length; j++) {
|
|
293
|
+
// let propertyName = Object.getOwnPropertyNames(schema.properties)[j];
|
|
294
|
+
// properties +=
|
|
295
|
+
// `
|
|
296
|
+
// ${this.toFirstLetterLowercase(propertyName)}: ${this.retrieveType(schema.properties[propertyName])} | undefined;`
|
|
297
|
+
// }
|
|
298
|
+
// return properties;
|
|
299
|
+
// }
|
|
300
|
+
// retrieveEnumValues(name: string, swaggerCopmponent: SwaggerComponent) {
|
|
301
|
+
// if (swaggerCopmponent.enum == null) return ``;
|
|
302
|
+
// let properties = ``;
|
|
303
|
+
// for (let index = 0; index < swaggerCopmponent.enum.length; index++) {
|
|
304
|
+
// const name = swaggerCopmponent.enum[index].split('-')[0].trim();
|
|
305
|
+
// const value = swaggerCopmponent.enum[index].split('-')[1].trim();
|
|
306
|
+
// properties +=
|
|
307
|
+
// `
|
|
308
|
+
// ${name} = ${value},`;
|
|
309
|
+
// }
|
|
310
|
+
// return properties;
|
|
311
|
+
// }
|
|
312
|
+
// retrieveNestedObjects(usedTypes: string[]) {
|
|
313
|
+
// for (let i = 0; i < usedTypes.length; i++) {
|
|
314
|
+
// const swaggerCopmponent = this._swagger.components.schemas[usedTypes[i]];
|
|
315
|
+
// // const name = usedTypes[i]
|
|
316
|
+
// // const modelName = <string>Object.getOwnPropertyNames(this._swagger.components.schemas)[name];
|
|
317
|
+
// this.retrieveNestedObjectsRecursive(swaggerCopmponent, usedTypes);
|
|
318
|
+
// }
|
|
319
|
+
// }
|
|
320
|
+
// retrieveNestedObjectsRecursive(swaggerComponent: SwaggerComponent, usedTypes: string[]) {
|
|
321
|
+
// if (!swaggerComponent.properties) return;
|
|
322
|
+
// for (let j = 0; j < Object.getOwnPropertyNames(swaggerComponent.properties).length; j++) {
|
|
323
|
+
// const propertyName = Object.getOwnPropertyNames(swaggerComponent.properties)[j];
|
|
324
|
+
// let nestedUsedType = '';
|
|
325
|
+
// if (swaggerComponent.properties[propertyName].$ref != null) {
|
|
326
|
+
// nestedUsedType = swaggerComponent.properties[propertyName].$ref.replace('#/components/schemas/', '');
|
|
327
|
+
// } else if (swaggerComponent.properties[propertyName].type == 'array' && swaggerComponent.properties[propertyName].items.$ref != null) {
|
|
328
|
+
// nestedUsedType = swaggerComponent.properties[propertyName].items.$ref.replace('#/components/schemas/', '');
|
|
329
|
+
// }
|
|
330
|
+
// if (nestedUsedType != '' && usedTypes.findIndex(x => x == nestedUsedType) == -1) {
|
|
331
|
+
// usedTypes.push(nestedUsedType);
|
|
332
|
+
// let nested = this._swagger.components.schemas[nestedUsedType];
|
|
333
|
+
// this.retrieveNestedObjectsRecursive(nested, usedTypes);
|
|
334
|
+
// }
|
|
335
|
+
// }
|
|
336
|
+
// }
|
|
337
|
+
// getNativeType(schema: SwaggerSchema): string {
|
|
338
|
+
// let nativeType = 'n.d.';
|
|
339
|
+
// if (schema.type == 'array') {
|
|
340
|
+
// nativeType = this.getNativeType(schema.items);
|
|
341
|
+
// nativeType += '[]';
|
|
342
|
+
// } else {
|
|
343
|
+
// if (schema.type == 'integer') nativeType = 'number';
|
|
344
|
+
// if (schema.type == 'string' && schema.format == null) nativeType = 'string';
|
|
345
|
+
// if (schema.type == 'string' && schema.format == 'date-time') nativeType = 'moment.Moment';
|
|
346
|
+
// if (schema.type == 'string' && schema.format == 'uuid') nativeType = 'string';
|
|
347
|
+
// if (schema.type == 'string' && schema.format == 'binary') nativeType = 'File';
|
|
348
|
+
// if (schema.type == 'number') nativeType = 'number';
|
|
349
|
+
// if (schema.type == 'boolean') nativeType = 'boolean';
|
|
350
|
+
// if (schema.type == 'object') nativeType = 'any';
|
|
351
|
+
// }
|
|
352
|
+
// if (nativeType.indexOf('n.d') == -1) {
|
|
353
|
+
// return nativeType;
|
|
354
|
+
// } else {
|
|
355
|
+
// console.error("unmanaged schema type", schema);
|
|
356
|
+
// throw new Error("unmanaged schema");
|
|
357
|
+
// }
|
|
358
|
+
// }
|
|
359
|
+
// getApiNameNormalized(apiName: string) {
|
|
360
|
+
// let normalizedApiName = apiName.replace('/api/v{version}/', '').replaceAll('/', '_');
|
|
361
|
+
// if (normalizedApiName.charAt(0) == '_') {
|
|
362
|
+
// normalizedApiName = normalizedApiName.slice(1);
|
|
363
|
+
// }
|
|
364
|
+
// return this.toFirstLetterLowercase(normalizedApiName);
|
|
365
|
+
// }
|
|
366
|
+
// toFirstLetterLowercase(value: string) {
|
|
367
|
+
// return value.charAt(0).toLowerCase() + value.slice(1);
|
|
368
|
+
// }
|
|
369
|
+
// }
|