@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?: number): Observable<Models.AirlineCompany> {
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: string): Observable<Models.AirlineCompanyListQueryResponse> {
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?`, httpOptions)
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?`, httpOptions)
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?`, httpOptions)
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?: number, serviceRequestType: Models.ServiceRequestTypeEnum): Observable<Models.TransportOrderListByServiceRequestQueryResponse> {
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.parametrizeObject(parameter.schema.$ref);
129
- //parameters += `${parameter.name}: ${parameter.schema.$ref.replace('#/components/schemas/', '')}&`;
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.replace('#/components/schemas/', '')}`;
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.replace('#/components/schemas/', '')}[]`;
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[objectName.replace('#/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
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
- 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
- let parametersString = this.retrieveParameters(swaggerMethodInfo);
33
- let queryParameters = this.retrieveQueryParameters(swaggerMethodInfo);
34
- let returnTypeString = this.retrieveReturnType(swaggerMethodInfo);
35
- if (returnTypeString == null) returnTypeString = 'void';
36
- let prepareRequestString = ``; //request = this._handleRequest(request);
37
- let haveRequest = swaggerMethodInfo.requestBody != null;
38
-
39
- if (haveRequest) {
40
- prepareRequestString = `request = this._handleRequest(request);
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
- apiMethods +=
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
- fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
57
- `${API_PRE}
60
+ fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts",
61
+ `${API_PRE}
58
62
  ${apiMethods}
59
63
  ${API_POST}`,
60
- { flag: 'w' });
61
- }
64
+ { flag: 'w' });
65
+ }
62
66
 
63
- generateModel() {
64
- let usedTypes: string[] = [];
67
+ generateModel() {
68
+ let usedTypes: string[] = [];
65
69
 
66
- for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
67
- const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
68
- const swaggerMethod = this._swagger.paths[apiName];
69
- const method = Object.getOwnPropertyNames(swaggerMethod)[0];
70
- const swaggerMethodInfo = swaggerMethod[method];
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
- // if(apiName == "/api/v{version}/Ticket/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
- usedTypes = usedTypes.concat(parametersRefType);
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
- if (swaggerMethodInfo.responses[200].content[contentType].schema.$ref != null) {
79
- usedTypes.push(swaggerMethodInfo.responses[200].content[contentType].schema.$ref.replace('#/components/schemas/', ''));
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
- if (swaggerMethodInfo.requestBody?.content[contentType]?.schema?.$ref) {
83
- usedTypes.push(swaggerMethodInfo.requestBody?.content[contentType]?.schema?.$ref.replace('#/components/schemas/', ''));
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
- this.retrieveNestedObjects(usedTypes);
91
+ this.retrieveNestedObjects(usedTypes);
88
92
 
89
- usedTypes = [...new Set(usedTypes.map(item => item))]; // [ 'A', 'B']
93
+ usedTypes = [...new Set(usedTypes.map(item => item))]; // [ 'A', 'B']
90
94
 
91
- // usedTypes = usedTypes.filter((value, index, array) => {
92
- // array.indexOf(value) === index;
93
- // });
94
- // usedTypes.forEach(element => {
95
- // console.debug(element);
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
- console.debug(`Start autogeneration Models`);
99
- let models = ``;
100
- for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.components.schemas).length; index++) {
101
- const modelName = Object.getOwnPropertyNames(this._swagger.components.schemas)[index];
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
- if (modelName == 'ActivatedVoucherSnackListResponse') {
104
- console.debug("ActivatedVoucherSnackListResponse");
105
- }
107
+ if (modelName == 'ActivatedVoucherSnackListResponse') {
108
+ console.debug("ActivatedVoucherSnackListResponse");
109
+ }
106
110
 
107
- if (usedTypes.indexOf(modelName) < 0) {
108
- console.debug(`\tModel SKIP - ${modelName}`);
109
- continue
110
- };
111
+ if (usedTypes.indexOf(modelName) < 0) {
112
+ console.debug(`\tModel SKIP - ${modelName}`);
113
+ continue
114
+ };
111
115
 
112
- const swaggerCopmponent = this._swagger.components.schemas[modelName];
116
+ const swaggerCopmponent = this._swagger.components.schemas[modelName];
113
117
 
114
- console.debug(`\tModel - ${modelName}`);
118
+ console.debug(`\tModel - ${modelName}`);
115
119
 
116
- let type = swaggerCopmponent.type == 'integer' ? 'enum' : 'class';
117
- let content = this.retrieveObjectContent(modelName, swaggerCopmponent);
120
+ let type = swaggerCopmponent.type == 'integer' ? 'enum' : 'class';
121
+ let content = this.retrieveObjectContent(modelName, swaggerCopmponent);
118
122
 
119
- models +=
120
- `
123
+ models +=
124
+ `
121
125
  export ${type} ${modelName} {${content}
122
126
  }
123
127
  `;
124
- }
128
+ }
125
129
 
126
- fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
127
- `${MODEL_PRE}
130
+ fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts",
131
+ `${MODEL_PRE}
128
132
  ${models}
129
133
  ${MODEL_POST}`,
130
- { flag: 'w' });
131
- }
132
-
133
- retrieveParameters(swaggerMethodInfo: SwaggerMethod) {
134
- if (swaggerMethodInfo.requestBody != null) {
135
- return `request: Models.${swaggerMethodInfo.requestBody.content[contentType].schema.$ref.replace('#/components/schemas/', '')}`
136
- }
137
-
138
- let parameters = ``;
139
- swaggerMethodInfo.parameters.filter(x => x.in == 'query').forEach(parameter => {
140
- if (parameter.schema.$ref != null) {
141
- parameters += `${this.toFirstLetterLowercase(parameter.name)}: Models.${parameter.schema.$ref.replace('#/components/schemas/', '')}, `;
142
- } else {
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
- parameters += `${this.toFirstLetterLowercase(parameter.name)}${nullable}: ${nativeType}, `;
146
- }
147
- });
149
+ parameters += `${this.toFirstLetterLowercase(parameter.name)}${nullable}: ${nativeType}, `;
150
+ }
151
+ });
148
152
 
149
- if (parameters.length > 2)
150
- parameters = parameters.substring(0, parameters.length - 2);
153
+ if (parameters.length > 2)
154
+ parameters = parameters.substring(0, parameters.length - 2);
151
155
 
152
- return parameters;
153
- }
154
-
155
- retrieveQueryParameters(swaggerMethodInfo: SwaggerMethod) {
156
- if (swaggerMethodInfo.requestBody != null) return ``;
156
+ return parameters;
157
+ }
157
158
 
158
- let filteredParameters = swaggerMethodInfo.parameters.filter(x => x.in == 'query');
159
- if (filteredParameters.length == 0) return ``;
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
- let parameters = `?`;
162
- filteredParameters.forEach(parameter => {
163
- if (parameter.schema.$ref != null) {
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
- if (parameters.length > 1)
172
- parameters = parameters.substring(0, parameters.length - 1);
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
- return parameters;
175
- }
191
+ if (swaggerMethodInfo.responses[200]?.content[contentType].schema.type != null)
192
+ return this.getNativeType(swaggerMethodInfo.responses[200]?.content[contentType].schema);
176
193
 
177
- retrieveReturnType(swaggerMethodInfo: SwaggerMethod) {
178
- if (swaggerMethodInfo.responses[200] == null)
179
- return 'void';
194
+ console.error("unmanaged swaggerMethodInfo", swaggerMethodInfo);
195
+ throw new Error("unmanaged swaggerMethodInfo");
196
+ }
180
197
 
181
- if (swaggerMethodInfo.responses[200].content[contentType].schema.$ref != null)
182
- return `Models.${swaggerMethodInfo.responses[200]?.content[contentType].schema.$ref.replace('#/components/schemas/', '')}`;
198
+ retrieveType(swaggerComponentProperty: SwaggerComponentProperty) {
199
+ if (swaggerComponentProperty.$ref != null)
200
+ return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
183
201
 
184
- if (swaggerMethodInfo.responses[200]?.content[contentType].schema.type != null)
185
- return this.getNativeType(swaggerMethodInfo.responses[200]?.content[contentType].schema);
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
- console.error("unmanaged swaggerMethodInfo", swaggerMethodInfo);
188
- throw new Error("unmanaged swaggerMethodInfo");
189
- }
208
+ if (swaggerComponentProperty.type != null)
209
+ return this.getNativeType(swaggerComponentProperty);
190
210
 
191
- retrieveType(swaggerComponentProperty: SwaggerComponentProperty) {
192
- if (swaggerComponentProperty.$ref != null)
193
- return swaggerComponentProperty.$ref.replace('#/components/schemas/', '');
211
+ if (swaggerComponentProperty.type == null)
212
+ return '';
194
213
 
195
- if (swaggerComponentProperty.type != null && swaggerComponentProperty.type == 'array')
196
- if (swaggerComponentProperty.items.$ref != null)
197
- return `${swaggerComponentProperty.items.$ref.replace('#/components/schemas/', '')}[]`;
198
- else
199
- return this.getNativeType(swaggerComponentProperty);
214
+ console.error("unmanaged swaggerMethodInfo", swaggerComponentProperty);
215
+ throw new Error("unmanaged swaggerMethodInfo");
216
+ }
200
217
 
201
- if (swaggerComponentProperty.type != null)
202
- return this.getNativeType(swaggerComponentProperty);
218
+ parametrizeObject(objectName: string) {
219
+ let component = this._swagger.components.schemas[this.getObjectName(objectName)];
203
220
 
204
- if (swaggerComponentProperty.type == null)
205
- return '';
221
+ if (component == null || component.properties == null) return ``;
206
222
 
207
- console.error("unmanaged swaggerMethodInfo", swaggerComponentProperty);
208
- throw new Error("unmanaged swaggerMethodInfo");
209
- }
223
+ console.debug(component.properties);
210
224
 
211
- parametrizeObject(objectName: string) {
212
- let component = this._swagger.components.schemas[objectName.replace('#/components/schemas/', '')];
213
- if (component == null || component.properties == null) return ``;
225
+ return ``;
226
+ }
214
227
 
215
- console.debug(component.properties);
228
+ isEnum(objectName: string) {
229
+ let component = this._swagger.components.schemas[this.getObjectName(objectName)];
230
+ return component.enum != null;
231
+ }
216
232
 
217
- return ``;
218
- }
233
+ getObjectName(ref: string) {
234
+ return ref.replace('#/components/schemas/', '');
235
+ }
219
236
 
220
- retrieveObjectContent(name: string, swaggerComponent: SwaggerComponent) {
221
- if (swaggerComponent.type == 'object')
222
- return this.retrieveObjectProperties(swaggerComponent);
223
- else if (swaggerComponent.type == 'integer')
224
- return this.retrieveEnumValues(name, swaggerComponent);
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
- retrieveObjectProperties(swaggerCopmponent: SwaggerComponent) {
228
- if (swaggerCopmponent.properties == null) return ``;
244
+ retrieveObjectProperties(swaggerCopmponent: SwaggerComponent) {
245
+ if (swaggerCopmponent.properties == null) return ``;
229
246
 
230
- // console.debug(`\t\t${Object.getOwnPropertyNames(swaggerCopmponent.properties).length}`);
247
+ // console.debug(`\t\t${Object.getOwnPropertyNames(swaggerCopmponent.properties).length}`);
231
248
 
232
- let properties = ``;
233
- for (let index = 0; index < Object.getOwnPropertyNames(swaggerCopmponent.properties).length; index++) {
234
- const propertyName = Object.getOwnPropertyNames(swaggerCopmponent.properties)[index];
235
- properties +=
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
- return properties;
241
- }
257
+ return properties;
258
+ }
242
259
 
243
- retrieveEnumValues(name: string, swaggerCopmponent: SwaggerComponent) {
244
- if (swaggerCopmponent.enum == null) return ``;
260
+ retrieveEnumValues(name: string, swaggerCopmponent: SwaggerComponent) {
261
+ if (swaggerCopmponent.enum == null) return ``;
245
262
 
246
- let properties = ``;
247
- for (let index = 0; index < swaggerCopmponent.enum.length; index++) {
248
- const name = swaggerCopmponent.enum[index].split('-')[0].trim();
249
- const value = swaggerCopmponent.enum[index].split('-')[1].trim();
250
- properties +=
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
- return properties;
256
- }
257
-
258
- retrieveNestedObjects(usedTypes: string[]) {
259
- for (let i = 0; i < usedTypes.length; i++) {
260
- const swaggerCopmponent = this._swagger.components.schemas[usedTypes[i]];
261
- // const name = usedTypes[i]
262
- // const modelName = <string>Object.getOwnPropertyNames(this._swagger.components.schemas)[name];
263
- this.retrieveNestedObjects2(swaggerCopmponent, usedTypes);
264
- }
265
- }
266
-
267
- retrieveNestedObjects2(swaggerComponent: SwaggerComponent, usedTypes: string[]) {
268
- if (!swaggerComponent.properties) return;
269
-
270
- for (let j = 0; j < Object.getOwnPropertyNames(swaggerComponent.properties).length; j++) {
271
- const propertyName = Object.getOwnPropertyNames(swaggerComponent.properties)[j];
272
- let nestedUsedType = '';
273
- if (swaggerComponent.properties[propertyName].$ref != null) {
274
- nestedUsedType = swaggerComponent.properties[propertyName].$ref.replace('#/components/schemas/', '');
275
- } else if (swaggerComponent.properties[propertyName].type == 'array' && swaggerComponent.properties[propertyName].items.$ref != null) {
276
- nestedUsedType = swaggerComponent.properties[propertyName].items.$ref.replace('#/components/schemas/', '');
277
- }
278
-
279
- if (nestedUsedType != '' && usedTypes.findIndex(x => x == nestedUsedType) == -1) {
280
- usedTypes.push(nestedUsedType);
281
- let nested = this._swagger.components.schemas[nestedUsedType];
282
- this.retrieveNestedObjects2(nested, usedTypes);
283
- }
284
- }
285
- }
286
-
287
- getNativeType(schema: SwaggerSchema): string {
288
- if (schema.type == 'integer') return 'number';
289
- if (schema.type == 'string' && schema.format == null) return 'string';
290
- if (schema.type == 'string' && schema.format == 'date-time') return 'moment.Moment';
291
- if (schema.type == 'string' && schema.format == 'uuid') return 'string';
292
- if (schema.type == 'number') return 'number';
293
- if (schema.type == 'array') return '[]';
294
- if (schema.type == 'boolean') return 'boolean';
295
- if (schema.type == 'object') return 'any';
296
-
297
- console.error("unmanaged schema type", schema);
298
- throw new Error("unmanaged schema");
299
- }
300
-
301
- toFirstLetterLowercase(value: string) {
302
- return value.charAt(0).toLowerCase() + value.slice(1);
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
  }