@devlearning/swagger-generator 1.0.13 → 1.0.16
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/dist/generator.js +2 -2
- package/dist/generators-writers/dart/api-dart-writer.js +3 -1
- package/dist/generators-writers/dart/model-dart-writer.js +2 -0
- package/dist/generators-writers/dart/templates/api.mustache +29 -0
- package/dist/generators-writers/dart/templates/model.mustache +18 -0
- package/dist/index.js +2 -2
- package/dist/templates/api.mustache +29 -0
- package/dist/templates/model.mustache +18 -0
- package/package.json +4 -2
- package/src/generator.ts +2 -2
- package/src/generators-writers/dart/api-dart-writer.ts +3 -2
- package/src/generators-writers/dart/model-dart-writer.ts +6 -4
- package/src/index.ts +2 -2
- package/dist/package.json +0 -37
- package/dist/src/api.constants.js +0 -24
- package/dist/src/generator-old.js +0 -369
- package/dist/src/generator.js +0 -425
- package/dist/src/generators-writers/angular/api-angular-writer.js +0 -113
- package/dist/src/generators-writers/angular/constants.js +0 -28
- package/dist/src/generators-writers/angular/model-angular-writer.js +0 -42
- package/dist/src/generators-writers/nextjs/api-nextjs-writer.js +0 -127
- package/dist/src/generators-writers/nextjs/constants.js +0 -5
- package/dist/src/generators-writers/nextjs/model-nextjs-writer.js +0 -41
- package/dist/src/generators-writers/utils.js +0 -20
- package/dist/src/index.js +0 -24
- package/dist/src/model.constants.js +0 -1
- package/dist/src/models/api-dto.js +0 -1
- package/dist/src/models/enum-value-dto.js +0 -1
- package/dist/src/models/model-dto.js +0 -1
- package/dist/src/models/parameter-dto.js +0 -1
- package/dist/src/models/property-dto.js +0 -1
- package/dist/src/models/swagger/swagger-component-property.js +0 -1
- package/dist/src/models/swagger/swagger-component.js +0 -1
- package/dist/src/models/swagger/swagger-content.js +0 -1
- package/dist/src/models/swagger/swagger-info.js +0 -1
- package/dist/src/models/swagger/swagger-method.js +0 -1
- package/dist/src/models/swagger/swagger-schema.js +0 -1
- package/dist/src/models/swagger/swagger.js +0 -1
- package/dist/src/models/type-dto.js +0 -1
- package/dist/src/swagger-downloader.js +0 -9
|
@@ -1,369 +0,0 @@
|
|
|
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
|
-
// }
|