@devlearning/swagger-generator 0.0.16 → 0.0.17
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.
|
@@ -14,7 +14,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
14
14
|
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
public AirlineCompany_Read(idAirlineCompany
|
|
17
|
+
public AirlineCompany_Read(idAirlineCompany: number): Observable<Models.AirlineCompany> {
|
|
18
18
|
return this._http.get<Models.AirlineCompany>(`${this._baseUrl}/api/v1/AirlineCompany/Read?idAirlineCompany=${idAirlineCompany}`, httpOptions)
|
|
19
19
|
.pipe(
|
|
20
20
|
map(x => this._handleResponse(x)),
|
|
@@ -22,7 +22,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public AirlineCompany_List(filter
|
|
25
|
+
public AirlineCompany_List(filter?: string): Observable<Models.AirlineCompanyListQueryResponse> {
|
|
26
26
|
return this._http.get<Models.AirlineCompanyListQueryResponse>(`${this._baseUrl}/api/v1/AirlineCompany/List?filter=${filter}`, httpOptions)
|
|
27
27
|
.pipe(
|
|
28
28
|
map(x => this._handleResponse(x)),
|
|
@@ -89,7 +89,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
public Airport_ListManaged(request: Models.AirportManagedListQuery): Observable<Models.AirportManagedListQueryResponse> {
|
|
92
|
-
return this._http.get<Models.AirportManagedListQueryResponse>(`${this._baseUrl}/api/v1/Airport/ListManaged
|
|
92
|
+
return this._http.get<Models.AirportManagedListQueryResponse>(`${this._baseUrl}/api/v1/Airport/ListManaged?request=${request}`, httpOptions)
|
|
93
93
|
.pipe(
|
|
94
94
|
map(x => this._handleResponse(x)),
|
|
95
95
|
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
@@ -131,7 +131,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
public Hotel_ListSummary(request: Models.HotelListSummaryQuery): Observable<Models.HotelListSummaryQueryResponse> {
|
|
134
|
-
return this._http.get<Models.HotelListSummaryQueryResponse>(`${this._baseUrl}/api/v1/Hotel/ListSummary
|
|
134
|
+
return this._http.get<Models.HotelListSummaryQueryResponse>(`${this._baseUrl}/api/v1/Hotel/ListSummary?request=${request}`, httpOptions)
|
|
135
135
|
.pipe(
|
|
136
136
|
map(x => this._handleResponse(x)),
|
|
137
137
|
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
@@ -147,7 +147,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
public HotelGroup_List(request: Models.HotelGroupListQuery): Observable<Models.HotelGroupListQueryResponse> {
|
|
150
|
-
return this._http.get<Models.HotelGroupListQueryResponse>(`${this._baseUrl}/api/v1/HotelGroup/List
|
|
150
|
+
return this._http.get<Models.HotelGroupListQueryResponse>(`${this._baseUrl}/api/v1/HotelGroup/List?request=${request}`, httpOptions)
|
|
151
151
|
.pipe(
|
|
152
152
|
map(x => this._handleResponse(x)),
|
|
153
153
|
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
@@ -674,8 +674,8 @@ export abstract class ApiAutogeneratedService {
|
|
|
674
674
|
);
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
public TransportOrder_ListByServiceRequest(idServiceRequest
|
|
678
|
-
return this._http.get<Models.TransportOrderListByServiceRequestQueryResponse>(`${this._baseUrl}/api/v1/TransportOrder/ListByServiceRequest?idServiceRequest=${idServiceRequest}`, httpOptions)
|
|
677
|
+
public TransportOrder_ListByServiceRequest(idServiceRequest: number, serviceRequestType: Models.ServiceRequestTypeEnum): Observable<Models.TransportOrderListByServiceRequestQueryResponse> {
|
|
678
|
+
return this._http.get<Models.TransportOrderListByServiceRequestQueryResponse>(`${this._baseUrl}/api/v1/TransportOrder/ListByServiceRequest?idServiceRequest=${idServiceRequest}&serviceRequestType=${serviceRequestType}`, httpOptions)
|
|
679
679
|
.pipe(
|
|
680
680
|
map(x => this._handleResponse(x)),
|
|
681
681
|
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
@@ -20,6 +20,8 @@ export class AirlineCompany {
|
|
|
20
20
|
idPassengerRegistrationTypeDefault: PassengerRegistrationTypeEnum | undefined;
|
|
21
21
|
name: string | undefined;
|
|
22
22
|
iataCode: string | undefined;
|
|
23
|
+
prefix: string | undefined;
|
|
24
|
+
phoneNumber: string | undefined;
|
|
23
25
|
notes: string | undefined;
|
|
24
26
|
}
|
|
25
27
|
|
package/dist/generator.js
CHANGED
|
@@ -18,6 +18,9 @@ export class Generator {
|
|
|
18
18
|
const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
19
19
|
const swaggerMethodInfo = swaggerMethod[method];
|
|
20
20
|
console.debug(`\tAPI - ${apiName} - ${method}`);
|
|
21
|
+
if (apiName == '/api/v{version}/TransportOrder/ListByServiceRequest') {
|
|
22
|
+
console.debug('');
|
|
23
|
+
}
|
|
21
24
|
let parametersString = this.retrieveParameters(swaggerMethodInfo);
|
|
22
25
|
let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
|
|
23
26
|
let returnTypeString = this.retrieveReturnType(swaggerMethodInfo);
|
|
@@ -125,8 +128,13 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
125
128
|
let parameters = `?`;
|
|
126
129
|
filteredParameters.forEach(parameter => {
|
|
127
130
|
if (parameter.schema.$ref != null) {
|
|
128
|
-
this.
|
|
129
|
-
|
|
131
|
+
if (this.isEnum(parameter.schema.$ref) != null) {
|
|
132
|
+
parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `}&`;
|
|
133
|
+
;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error("retrieveQueryParameters unmanaged parameter.schema.$ref");
|
|
137
|
+
}
|
|
130
138
|
}
|
|
131
139
|
else {
|
|
132
140
|
parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `}&`;
|
|
@@ -140,7 +148,7 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
140
148
|
if (swaggerMethodInfo.responses[200] == null)
|
|
141
149
|
return 'void';
|
|
142
150
|
if (swaggerMethodInfo.responses[200].content[contentType].schema.$ref != null)
|
|
143
|
-
return `Models.${swaggerMethodInfo.responses[200]?.content[contentType].schema.$ref
|
|
151
|
+
return `Models.${this.getObjectName(swaggerMethodInfo.responses[200]?.content[contentType].schema.$ref)}`;
|
|
144
152
|
if (swaggerMethodInfo.responses[200]?.content[contentType].schema.type != null)
|
|
145
153
|
return this.getNativeType(swaggerMethodInfo.responses[200]?.content[contentType].schema);
|
|
146
154
|
console.error("unmanaged swaggerMethodInfo", swaggerMethodInfo);
|
|
@@ -151,7 +159,7 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
151
159
|
return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
|
|
152
160
|
if (swaggerComponentProperty.type != null && swaggerComponentProperty.type == 'array')
|
|
153
161
|
if (swaggerComponentProperty.items.$ref != null)
|
|
154
|
-
return `${swaggerComponentProperty.items.$ref
|
|
162
|
+
return `${this.getObjectName(swaggerComponentProperty.items.$ref)}[]`;
|
|
155
163
|
else
|
|
156
164
|
return this.getNativeType(swaggerComponentProperty);
|
|
157
165
|
if (swaggerComponentProperty.type != null)
|
|
@@ -162,12 +170,19 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
162
170
|
throw new Error("unmanaged swaggerMethodInfo");
|
|
163
171
|
}
|
|
164
172
|
parametrizeObject(objectName) {
|
|
165
|
-
let component = this._swagger.components.schemas[
|
|
173
|
+
let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
166
174
|
if (component == null || component.properties == null)
|
|
167
175
|
return ``;
|
|
168
176
|
console.debug(component.properties);
|
|
169
177
|
return ``;
|
|
170
178
|
}
|
|
179
|
+
isEnum(objectName) {
|
|
180
|
+
let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
181
|
+
return component.enum != null;
|
|
182
|
+
}
|
|
183
|
+
getObjectName(ref) {
|
|
184
|
+
return ref.replace('#/components/schemas/', '');
|
|
185
|
+
}
|
|
171
186
|
retrieveObjectContent(name, swaggerComponent) {
|
|
172
187
|
if (swaggerComponent.type == 'object')
|
|
173
188
|
return this.retrieveObjectProperties(swaggerComponent);
|
package/package.json
CHANGED
package/src/generator.ts
CHANGED
|
@@ -10,39 +10,43 @@ import { MODEL_POST, MODEL_PRE } from './model.constants.js';
|
|
|
10
10
|
const contentType = 'application/json';
|
|
11
11
|
|
|
12
12
|
export class Generator {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
private _swagger: Swagger;
|
|
14
|
+
private _outputDirectory: string;
|
|
15
|
+
|
|
16
|
+
constructor(swagger: Swagger, outputDirectory: string) {
|
|
17
|
+
this._swagger = swagger;
|
|
18
|
+
this._outputDirectory = outputDirectory;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
generateApi() {
|
|
22
|
+
console.debug(`Start autogeneration Apis`);
|
|
23
|
+
|
|
24
|
+
let apiMethods = ``;
|
|
25
|
+
for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
|
|
26
|
+
const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
|
|
27
|
+
const swaggerMethod = this._swagger.paths[apiName];
|
|
28
|
+
const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
29
|
+
const swaggerMethodInfo = swaggerMethod[method];
|
|
30
|
+
console.debug(`\tAPI - ${apiName} - ${method}`);
|
|
31
|
+
|
|
32
|
+
if (apiName == '/api/v{version}/TransportOrder/ListByServiceRequest') {
|
|
33
|
+
console.debug('');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let parametersString = this.retrieveParameters(swaggerMethodInfo);
|
|
37
|
+
let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
|
|
38
|
+
let returnTypeString = this.retrieveReturnType(swaggerMethodInfo);
|
|
39
|
+
if (returnTypeString == null) returnTypeString = 'void';
|
|
40
|
+
let prepareRequestString = ``; //request = this._handleRequest(request);
|
|
41
|
+
let haveRequest = swaggerMethodInfo.requestBody != null;
|
|
42
|
+
|
|
43
|
+
if (haveRequest) {
|
|
44
|
+
prepareRequestString = `request = this._handleRequest(request);
|
|
41
45
|
`;
|
|
42
|
-
|
|
46
|
+
}
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
apiMethods +=
|
|
49
|
+
`
|
|
46
50
|
public ${apiName.replace('/api/v{version}/', '').replaceAll('/', '_')}(${parametersString}): Observable<${returnTypeString}> {
|
|
47
51
|
${prepareRequestString}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${apiName.replace('{version}', '1')}${queryParameters}\`${haveRequest ? ', request' : ''}, httpOptions)
|
|
48
52
|
.pipe(
|
|
@@ -51,254 +55,267 @@ export class Generator {
|
|
|
51
55
|
);
|
|
52
56
|
}
|
|
53
57
|
`;
|
|
54
|
-
|
|
58
|
+
}
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
|
|
61
|
+
`${API_PRE}
|
|
58
62
|
${apiMethods}
|
|
59
63
|
${API_POST}`,
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
{ flag: 'w' });
|
|
65
|
+
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
generateModel() {
|
|
68
|
+
let usedTypes: string[] = [];
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
|
|
71
|
+
const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
|
|
72
|
+
const swaggerMethod = this._swagger.paths[apiName];
|
|
73
|
+
const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
74
|
+
const swaggerMethodInfo = swaggerMethod[method];
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
// if(apiName == "/api/v{version}/Ticket/Create"){
|
|
77
|
+
// debugger
|
|
78
|
+
// }
|
|
79
|
+
let parametersRefType = swaggerMethodInfo.parameters.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''))
|
|
80
|
+
usedTypes = usedTypes.concat(parametersRefType);
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (swaggerMethodInfo.responses[200].content[contentType].schema.$ref != null) {
|
|
83
|
+
usedTypes.push(swaggerMethodInfo.responses[200].content[contentType].schema.$ref.replace('#/components/schemas/', ''));
|
|
84
|
+
}
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if (swaggerMethodInfo.requestBody?.content[contentType]?.schema?.$ref) {
|
|
87
|
+
usedTypes.push(swaggerMethodInfo.requestBody?.content[contentType]?.schema?.$ref.replace('#/components/schemas/', ''));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
this.retrieveNestedObjects(usedTypes);
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
usedTypes = [...new Set(usedTypes.map(item => item))]; // [ 'A', 'B']
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// usedTypes = usedTypes.filter((value, index, array) => {
|
|
96
|
+
// array.indexOf(value) === index;
|
|
97
|
+
// });
|
|
98
|
+
// usedTypes.forEach(element => {
|
|
99
|
+
// console.debug(element);
|
|
100
|
+
// });
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
console.debug(`Start autogeneration Models`);
|
|
103
|
+
let models = ``;
|
|
104
|
+
for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.components.schemas).length; index++) {
|
|
105
|
+
const modelName = Object.getOwnPropertyNames(this._swagger.components.schemas)[index];
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
if (modelName == 'ActivatedVoucherSnackListResponse') {
|
|
108
|
+
console.debug("ActivatedVoucherSnackListResponse");
|
|
109
|
+
}
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
if (usedTypes.indexOf(modelName) < 0) {
|
|
112
|
+
console.debug(`\tModel SKIP - ${modelName}`);
|
|
113
|
+
continue
|
|
114
|
+
};
|
|
111
115
|
|
|
112
|
-
|
|
116
|
+
const swaggerCopmponent = this._swagger.components.schemas[modelName];
|
|
113
117
|
|
|
114
|
-
|
|
118
|
+
console.debug(`\tModel - ${modelName}`);
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
let type = swaggerCopmponent.type == 'integer' ? 'enum' : 'class';
|
|
121
|
+
let content = this.retrieveObjectContent(modelName, swaggerCopmponent);
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
models +=
|
|
124
|
+
`
|
|
121
125
|
export ${type} ${modelName} {${content}
|
|
122
126
|
}
|
|
123
127
|
`;
|
|
124
|
-
|
|
128
|
+
}
|
|
125
129
|
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
|
|
131
|
+
`${MODEL_PRE}
|
|
128
132
|
${models}
|
|
129
133
|
${MODEL_POST}`,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
{ flag: 'w' });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
retrieveParameters(swaggerMethodInfo: SwaggerMethod) {
|
|
138
|
+
if (swaggerMethodInfo.requestBody != null) {
|
|
139
|
+
return `request: Models.${swaggerMethodInfo.requestBody.content[contentType].schema.$ref.replace('#/components/schemas/', '')}`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let parameters = ``;
|
|
143
|
+
swaggerMethodInfo.parameters.filter(x => x.in == 'query').forEach(parameter => {
|
|
144
|
+
if (parameter.schema.$ref != null) {
|
|
145
|
+
parameters += `${this.toFirstLetterLowercase(parameter.name)}: Models.${parameter.schema.$ref.replace('#/components/schemas/', '')}, `;
|
|
146
|
+
} else {
|
|
143
147
|
const nativeType = this.getNativeType(parameter.schema);
|
|
144
148
|
const nullable = !parameter.required ? '?' : '';
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
parameters += `${this.toFirstLetterLowercase(parameter.name)}${nullable}: ${nativeType}, `;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
if (parameters.length > 2)
|
|
154
|
+
parameters = parameters.substring(0, parameters.length - 2);
|
|
151
155
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
retrieveQueryParameters(swaggerMethodInfo: SwaggerMethod) {
|
|
156
|
-
if (swaggerMethodInfo.requestBody != null) return ``;
|
|
156
|
+
return parameters;
|
|
157
|
+
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
retrieveQueryParameters(swaggerMethodInfo: SwaggerMethod) {
|
|
160
|
+
if (swaggerMethodInfo.requestBody != null) return ``;
|
|
161
|
+
|
|
162
|
+
let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
|
|
163
|
+
if (filteredParameters.length == 0) return ``;
|
|
164
|
+
|
|
165
|
+
let parameters = `?`;
|
|
166
|
+
filteredParameters.forEach(parameter => {
|
|
167
|
+
if (parameter.schema.$ref != null) {
|
|
168
|
+
if (this.isEnum(parameter.schema.$ref) != null) {
|
|
169
|
+
parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `}&`;;
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error("retrieveQueryParameters unmanaged parameter.schema.$ref");
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `}&`;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (parameters.length > 1)
|
|
179
|
+
parameters = parameters.substring(0, parameters.length - 1);
|
|
180
|
+
|
|
181
|
+
return parameters;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.parametrizeObject(parameter.schema.$ref)
|
|
165
|
-
//parameters += `${parameter.name}: ${parameter.schema.$ref.replace('#/components/schemas/', '')}&`;
|
|
166
|
-
} else {
|
|
167
|
-
parameters += `${this.toFirstLetterLowercase(parameter.name)}=\${` + this.toFirstLetterLowercase(parameter.name) + `}&`;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
184
|
+
retrieveReturnType(swaggerMethodInfo: SwaggerMethod) {
|
|
185
|
+
if (swaggerMethodInfo.responses[200] == null)
|
|
186
|
+
return 'void';
|
|
170
187
|
|
|
171
|
-
|
|
172
|
-
|
|
188
|
+
if (swaggerMethodInfo.responses[200].content[contentType].schema.$ref != null)
|
|
189
|
+
return `Models.${this.getObjectName(swaggerMethodInfo.responses[200]?.content[contentType].schema.$ref)}`;
|
|
173
190
|
|
|
174
|
-
|
|
175
|
-
|
|
191
|
+
if (swaggerMethodInfo.responses[200]?.content[contentType].schema.type != null)
|
|
192
|
+
return this.getNativeType(swaggerMethodInfo.responses[200]?.content[contentType].schema);
|
|
176
193
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
console.error("unmanaged swaggerMethodInfo", swaggerMethodInfo);
|
|
195
|
+
throw new Error("unmanaged swaggerMethodInfo");
|
|
196
|
+
}
|
|
180
197
|
|
|
181
|
-
|
|
182
|
-
|
|
198
|
+
retrieveType(swaggerComponentProperty: SwaggerComponentProperty) {
|
|
199
|
+
if (swaggerComponentProperty.$ref != null)
|
|
200
|
+
return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
|
|
183
201
|
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
if (swaggerComponentProperty.type != null && swaggerComponentProperty.type == 'array')
|
|
203
|
+
if (swaggerComponentProperty.items.$ref != null)
|
|
204
|
+
return `${this.getObjectName(swaggerComponentProperty.items.$ref)}[]`;
|
|
205
|
+
else
|
|
206
|
+
return this.getNativeType(swaggerComponentProperty);
|
|
186
207
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
208
|
+
if (swaggerComponentProperty.type != null)
|
|
209
|
+
return this.getNativeType(swaggerComponentProperty);
|
|
190
210
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
|
|
211
|
+
if (swaggerComponentProperty.type == null)
|
|
212
|
+
return '';
|
|
194
213
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
else
|
|
199
|
-
return this.getNativeType(swaggerComponentProperty);
|
|
214
|
+
console.error("unmanaged swaggerMethodInfo", swaggerComponentProperty);
|
|
215
|
+
throw new Error("unmanaged swaggerMethodInfo");
|
|
216
|
+
}
|
|
200
217
|
|
|
201
|
-
|
|
202
|
-
|
|
218
|
+
parametrizeObject(objectName: string) {
|
|
219
|
+
let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
203
220
|
|
|
204
|
-
|
|
205
|
-
return '';
|
|
221
|
+
if (component == null || component.properties == null) return ``;
|
|
206
222
|
|
|
207
|
-
|
|
208
|
-
throw new Error("unmanaged swaggerMethodInfo");
|
|
209
|
-
}
|
|
223
|
+
console.debug(component.properties);
|
|
210
224
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (component == null || component.properties == null) return ``;
|
|
225
|
+
return ``;
|
|
226
|
+
}
|
|
214
227
|
|
|
215
|
-
|
|
228
|
+
isEnum(objectName: string) {
|
|
229
|
+
let component = this._swagger.components.schemas[this.getObjectName(objectName)];
|
|
230
|
+
return component.enum != null;
|
|
231
|
+
}
|
|
216
232
|
|
|
217
|
-
|
|
218
|
-
|
|
233
|
+
getObjectName(ref: string) {
|
|
234
|
+
return ref.replace('#/components/schemas/', '');
|
|
235
|
+
}
|
|
219
236
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
retrieveObjectContent(name: string, swaggerComponent: SwaggerComponent) {
|
|
238
|
+
if (swaggerComponent.type == 'object')
|
|
239
|
+
return this.retrieveObjectProperties(swaggerComponent);
|
|
240
|
+
else if (swaggerComponent.type == 'integer')
|
|
241
|
+
return this.retrieveEnumValues(name, swaggerComponent);
|
|
242
|
+
}
|
|
226
243
|
|
|
227
|
-
|
|
228
|
-
|
|
244
|
+
retrieveObjectProperties(swaggerCopmponent: SwaggerComponent) {
|
|
245
|
+
if (swaggerCopmponent.properties == null) return ``;
|
|
229
246
|
|
|
230
|
-
|
|
247
|
+
// console.debug(`\t\t${Object.getOwnPropertyNames(swaggerCopmponent.properties).length}`);
|
|
231
248
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
249
|
+
let properties = ``;
|
|
250
|
+
for (let index = 0; index < Object.getOwnPropertyNames(swaggerCopmponent.properties).length; index++) {
|
|
251
|
+
const propertyName = Object.getOwnPropertyNames(swaggerCopmponent.properties)[index];
|
|
252
|
+
properties +=
|
|
253
|
+
`
|
|
237
254
|
${propertyName}: ${this.retrieveType(swaggerCopmponent.properties[propertyName])} | undefined;`
|
|
238
|
-
|
|
255
|
+
}
|
|
239
256
|
|
|
240
|
-
|
|
241
|
-
|
|
257
|
+
return properties;
|
|
258
|
+
}
|
|
242
259
|
|
|
243
|
-
|
|
244
|
-
|
|
260
|
+
retrieveEnumValues(name: string, swaggerCopmponent: SwaggerComponent) {
|
|
261
|
+
if (swaggerCopmponent.enum == null) return ``;
|
|
245
262
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
let properties = ``;
|
|
264
|
+
for (let index = 0; index < swaggerCopmponent.enum.length; index++) {
|
|
265
|
+
const name = swaggerCopmponent.enum[index].split('-')[0].trim();
|
|
266
|
+
const value = swaggerCopmponent.enum[index].split('-')[1].trim();
|
|
267
|
+
properties +=
|
|
268
|
+
`
|
|
252
269
|
${name} = ${value},`;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return properties;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
retrieveNestedObjects(usedTypes: string[]) {
|
|
276
|
+
for (let i = 0; i < usedTypes.length; i++) {
|
|
277
|
+
const swaggerCopmponent = this._swagger.components.schemas[usedTypes[i]];
|
|
278
|
+
// const name = usedTypes[i]
|
|
279
|
+
// const modelName = <string>Object.getOwnPropertyNames(this._swagger.components.schemas)[name];
|
|
280
|
+
this.retrieveNestedObjects2(swaggerCopmponent, usedTypes);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
retrieveNestedObjects2(swaggerComponent: SwaggerComponent, usedTypes: string[]) {
|
|
285
|
+
if (!swaggerComponent.properties) return;
|
|
286
|
+
|
|
287
|
+
for (let j = 0; j < Object.getOwnPropertyNames(swaggerComponent.properties).length; j++) {
|
|
288
|
+
const propertyName = Object.getOwnPropertyNames(swaggerComponent.properties)[j];
|
|
289
|
+
let nestedUsedType = '';
|
|
290
|
+
if (swaggerComponent.properties[propertyName].$ref != null) {
|
|
291
|
+
nestedUsedType = swaggerComponent.properties[propertyName].$ref.replace('#/components/schemas/', '');
|
|
292
|
+
} else if (swaggerComponent.properties[propertyName].type == 'array' && swaggerComponent.properties[propertyName].items.$ref != null) {
|
|
293
|
+
nestedUsedType = swaggerComponent.properties[propertyName].items.$ref.replace('#/components/schemas/', '');
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (nestedUsedType != '' && usedTypes.findIndex(x => x == nestedUsedType) == -1) {
|
|
297
|
+
usedTypes.push(nestedUsedType);
|
|
298
|
+
let nested = this._swagger.components.schemas[nestedUsedType];
|
|
299
|
+
this.retrieveNestedObjects2(nested, usedTypes);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
getNativeType(schema: SwaggerSchema): string {
|
|
305
|
+
if (schema.type == 'integer') return 'number';
|
|
306
|
+
if (schema.type == 'string' && schema.format == null) return 'string';
|
|
307
|
+
if (schema.type == 'string' && schema.format == 'date-time') return 'moment.Moment';
|
|
308
|
+
if (schema.type == 'string' && schema.format == 'uuid') return 'string';
|
|
309
|
+
if (schema.type == 'number') return 'number';
|
|
310
|
+
if (schema.type == 'array') return '[]';
|
|
311
|
+
if (schema.type == 'boolean') return 'boolean';
|
|
312
|
+
if (schema.type == 'object') return 'any';
|
|
313
|
+
|
|
314
|
+
console.error("unmanaged schema type", schema);
|
|
315
|
+
throw new Error("unmanaged schema");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
toFirstLetterLowercase(value: string) {
|
|
319
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
320
|
+
}
|
|
304
321
|
}
|