@devlearning/swagger-generator 1.1.23 → 1.1.25

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.
@@ -41,5 +41,7 @@ export declare class Generator {
41
41
  retrieveNestedObjectsRecursive(swaggerComponent: SwaggerComponent, usedTypes: TypeDto[]): void;
42
42
  getNativeType(schema: SwaggerSchema): string;
43
43
  getApiNameNormalized(apiName: string): string;
44
+ private getMultipartModelName;
45
+ private getMultipartModelNameForTarget;
44
46
  toFirstLetterLowercase(value: string): string;
45
47
  }
package/dist/generator.js CHANGED
@@ -133,9 +133,9 @@ export class Generator {
133
133
  return;
134
134
  }
135
135
  this._models.push({
136
- typeName: this.getApiNameNormalized(apiName),
136
+ typeName: this.getMultipartModelNameForTarget(apiName),
137
137
  modelType: 'class',
138
- name: this.getApiNameNormalized(apiName),
138
+ name: this.getMultipartModelNameForTarget(apiName),
139
139
  properties: this.retrieveSchemaProperties(schema),
140
140
  enumValues: [],
141
141
  });
@@ -217,18 +217,33 @@ export class Generator {
217
217
  });
218
218
  if (swaggerMethod.requestBody != null && swaggerMethod.requestBody.content[contentTypeMultipartFormData] != null) {
219
219
  const schema = swaggerMethod.requestBody.content[contentTypeMultipartFormData].schema;
220
- const type = this.retrieveType(schema);
221
- parameters.unshift({
222
- name: 'request',
223
- typeName: type.typeName,
224
- nullable: false,
225
- isQuery: false,
226
- isEnum: false,
227
- isTypeReference: type.isTypeReference ?? true,
228
- isNativeType: type.isNativeType ?? false,
229
- isArray: type.isArray ?? false,
230
- isVoid: type.isVoid ?? false,
231
- });
220
+ if (schema?.$ref == null && schema?.type === 'object') {
221
+ parameters.unshift({
222
+ name: 'request',
223
+ typeName: this.getMultipartModelNameForTarget(apiName),
224
+ nullable: false,
225
+ isQuery: false,
226
+ isEnum: false,
227
+ isTypeReference: true,
228
+ isNativeType: false,
229
+ isArray: false,
230
+ isVoid: false,
231
+ });
232
+ }
233
+ else {
234
+ const type = this.retrieveType(schema);
235
+ parameters.unshift({
236
+ name: 'request',
237
+ typeName: type.typeName,
238
+ nullable: false,
239
+ isQuery: false,
240
+ isEnum: false,
241
+ isTypeReference: type.isTypeReference ?? true,
242
+ isNativeType: type.isNativeType ?? false,
243
+ isArray: type.isArray ?? false,
244
+ isVoid: type.isVoid ?? false,
245
+ });
246
+ }
232
247
  }
233
248
  else {
234
249
  if (swaggerMethod.requestBody != null) {
@@ -675,6 +690,16 @@ export class Generator {
675
690
  }
676
691
  return normalizedApiName;
677
692
  }
693
+ getMultipartModelName(apiName) {
694
+ return Utils.toPascalCase(Utils.getNormalizedApiPathAngular(apiName));
695
+ }
696
+ getMultipartModelNameForTarget(apiName) {
697
+ if (this._commandLineArgs.target === TargetGeneration.Angular) {
698
+ return this.getMultipartModelName(apiName);
699
+ }
700
+ // Preserve pre-existing naming for non-Angular targets.
701
+ return this.getApiNameNormalized(apiName);
702
+ }
678
703
  toFirstLetterLowercase(value) {
679
704
  return value.charAt(0).toLowerCase() + value.slice(1);
680
705
  }
@@ -12,6 +12,7 @@ export declare class ApiAngularWriter {
12
12
  private _queryParameters;
13
13
  private _queryParametersStatement;
14
14
  private _requestPreparation;
15
+ private _isIgnoredAngularParameter;
15
16
  private _writeFile;
16
17
  private _getApiPre;
17
18
  }
@@ -41,6 +41,9 @@ export class ApiAngularWriter {
41
41
  _parameters(api) {
42
42
  let parametersString = '';
43
43
  api.parameters.forEach(parameter => {
44
+ if (this._isIgnoredAngularParameter(parameter)) {
45
+ return;
46
+ }
44
47
  const libraryDate = 'moment.Moment';
45
48
  const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
46
49
  const typeName = parameter.typeName === 'dateTime' ? libraryDate : `${prefixType}${Normalizator.mapTsTypeToAngular(parameter.typeName)}`;
@@ -59,6 +62,9 @@ export class ApiAngularWriter {
59
62
  _queryParametersPreparation(api) {
60
63
  let queryParametersPreparation = '';
61
64
  api.parameters.forEach(parameter => {
65
+ if (this._isIgnoredAngularParameter(parameter)) {
66
+ return;
67
+ }
62
68
  if (parameter.isQuery) {
63
69
  queryParametersPreparation += this._queryParametersPreparationStatement(parameter);
64
70
  }
@@ -90,6 +96,9 @@ export class ApiAngularWriter {
90
96
  _queryParameters(api) {
91
97
  let queryParameters = '';
92
98
  api.parameters.forEach(parameter => {
99
+ if (this._isIgnoredAngularParameter(parameter)) {
100
+ return;
101
+ }
93
102
  if (parameter.isQuery) {
94
103
  queryParameters += this._queryParametersStatement(parameter);
95
104
  }
@@ -119,6 +128,9 @@ export class ApiAngularWriter {
119
128
  `;
120
129
  }
121
130
  }
131
+ _isIgnoredAngularParameter(parameter) {
132
+ return parameter.name?.toLowerCase() === 'version';
133
+ }
122
134
  _writeFile(apis) {
123
135
  const className = this._commandLineArgs.apiClientName || 'ApiAutogeneratedService';
124
136
  const apiPre = this._getApiPre(className);
@@ -148,7 +160,7 @@ export abstract class ${className} {
148
160
  protected abstract _handleRequest<T>(request: T): T;
149
161
  protected abstract _handleMultipart<T>(request: T): FormData;
150
162
  protected abstract _handleResponse<T>(response: T): T;
151
- protected abstract _handleError(error: any, obs: any): Observable<never>;
163
+ protected abstract _handleError(error: any, obs: any, skipErrorHandling: boolean): Observable<never>;
152
164
  `;
153
165
  }
154
166
  }
@@ -1,4 +1,3 @@
1
- export declare const API_PRE = "import { HttpClient } from '@angular/common/http';\nimport { Observable, catchError, map } from 'rxjs';\nimport * as Models from './model.autogenerated';\nimport { HttpHeaders } from \"@angular/common/http\";\n\nexport const httpOptions = {\n headers: new HttpHeaders({ 'Content-Type': 'application/json' }),\n};\n\nexport const httpOptionsMultipart = {};\n\nexport abstract class ApiAutogeneratedService {\n constructor(\n public _http: HttpClient,\n public _baseUrl: string,\n ) { }\n\n protected abstract _momentToString(moment: moment.Moment): string;\n protected abstract _handleRequest<T>(request: T): T;\n protected abstract _handleMultipart<T>(request: T): FormData;\n protected abstract _handleResponse<T>(response: T): T;\n protected abstract _handleError<T>(error: any, obs: Observable<T>, skipErrorHandling: boolean): Observable<never>;\n";
2
1
  export declare const API_POST = "}";
3
2
  export declare const MODEL_PRE = "import * as moment from 'moment';\n ";
4
3
  export declare const MODEL_POST = "\n";
@@ -1,26 +1,3 @@
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<T>(error: any, obs: Observable<T>, skipErrorHandling: boolean): Observable<never>;
23
- `;
24
1
  export const API_POST = `}`;
25
2
  export const MODEL_PRE = `import * as moment from 'moment';
26
3
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "1.1.23",
3
+ "version": "1.1.25",
4
4
  "description": "Swagger generator apis and models for Angular and NextJS",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/generator.ts CHANGED
@@ -175,9 +175,9 @@ export class Generator {
175
175
  }
176
176
 
177
177
  this._models.push({
178
- typeName: this.getApiNameNormalized(apiName),
178
+ typeName: this.getMultipartModelNameForTarget(apiName),
179
179
  modelType: 'class',
180
- name: this.getApiNameNormalized(apiName),
180
+ name: this.getMultipartModelNameForTarget(apiName),
181
181
  properties: this.retrieveSchemaProperties(schema),
182
182
  enumValues: [],
183
183
  });
@@ -264,18 +264,32 @@ export class Generator {
264
264
 
265
265
  if (swaggerMethod.requestBody != null && swaggerMethod.requestBody.content[contentTypeMultipartFormData] != null) {
266
266
  const schema = swaggerMethod.requestBody.content[contentTypeMultipartFormData].schema;
267
- const type = this.retrieveType(schema);
268
- parameters.unshift({
269
- name: 'request',
270
- typeName: type.typeName,
271
- nullable: false,
272
- isQuery: false,
273
- isEnum: false,
274
- isTypeReference: type.isTypeReference ?? true,
275
- isNativeType: type.isNativeType ?? false,
276
- isArray: type.isArray ?? false,
277
- isVoid: type.isVoid ?? false,
278
- });
267
+ if (schema?.$ref == null && schema?.type === 'object') {
268
+ parameters.unshift({
269
+ name: 'request',
270
+ typeName: this.getMultipartModelNameForTarget(apiName),
271
+ nullable: false,
272
+ isQuery: false,
273
+ isEnum: false,
274
+ isTypeReference: true,
275
+ isNativeType: false,
276
+ isArray: false,
277
+ isVoid: false,
278
+ });
279
+ } else {
280
+ const type = this.retrieveType(schema);
281
+ parameters.unshift({
282
+ name: 'request',
283
+ typeName: type.typeName,
284
+ nullable: false,
285
+ isQuery: false,
286
+ isEnum: false,
287
+ isTypeReference: type.isTypeReference ?? true,
288
+ isNativeType: type.isNativeType ?? false,
289
+ isArray: type.isArray ?? false,
290
+ isVoid: type.isVoid ?? false,
291
+ });
292
+ }
279
293
  } else {
280
294
  if (swaggerMethod.requestBody != null) {
281
295
  const type = this.retrieveType(swaggerMethod.requestBody.content[contentTypeApplicationJson].schema);
@@ -747,6 +761,19 @@ export class Generator {
747
761
  return normalizedApiName;
748
762
  }
749
763
 
764
+ private getMultipartModelName(apiName: string): string {
765
+ return Utils.toPascalCase(Utils.getNormalizedApiPathAngular(apiName));
766
+ }
767
+
768
+ private getMultipartModelNameForTarget(apiName: string): string {
769
+ if (this._commandLineArgs.target === TargetGeneration.Angular) {
770
+ return this.getMultipartModelName(apiName);
771
+ }
772
+
773
+ // Preserve pre-existing naming for non-Angular targets.
774
+ return this.getApiNameNormalized(apiName);
775
+ }
776
+
750
777
  toFirstLetterLowercase(value: string) {
751
778
  return value.charAt(0).toLowerCase() + value.slice(1);
752
779
  }
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import { API_POST, API_PRE } from './constants.js';
2
+ import { API_POST } from './constants.js';
3
3
  import { ApiDto } from '../../models/api-dto.js';
4
4
  import { Utils } from '../utils.js';
5
5
  import { ParameterDto } from '../../models/parameter-dto.js';
@@ -58,6 +58,10 @@ export class ApiAngularWriter {
58
58
  let parametersString = '';
59
59
 
60
60
  api.parameters.forEach(parameter => {
61
+ if (this._isIgnoredAngularParameter(parameter)) {
62
+ return;
63
+ }
64
+
61
65
  const libraryDate = 'moment.Moment';
62
66
  const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
63
67
  const typeName = parameter.typeName === 'dateTime' ? libraryDate : `${prefixType}${Normalizator.mapTsTypeToAngular(parameter.typeName)}`;
@@ -83,6 +87,10 @@ export class ApiAngularWriter {
83
87
  let queryParametersPreparation = '';
84
88
 
85
89
  api.parameters.forEach(parameter => {
90
+ if (this._isIgnoredAngularParameter(parameter)) {
91
+ return;
92
+ }
93
+
86
94
  if (parameter.isQuery) {
87
95
  queryParametersPreparation += this._queryParametersPreparationStatement(parameter);
88
96
  }
@@ -115,6 +123,10 @@ export class ApiAngularWriter {
115
123
  let queryParameters = '';
116
124
 
117
125
  api.parameters.forEach(parameter => {
126
+ if (this._isIgnoredAngularParameter(parameter)) {
127
+ return;
128
+ }
129
+
118
130
  if (parameter.isQuery) {
119
131
  queryParameters += this._queryParametersStatement(parameter);
120
132
  }
@@ -149,6 +161,10 @@ export class ApiAngularWriter {
149
161
  }
150
162
  }
151
163
 
164
+ private _isIgnoredAngularParameter(parameter: ParameterDto): boolean {
165
+ return parameter.name?.toLowerCase() === 'version';
166
+ }
167
+
152
168
  private _writeFile(apis: string) {
153
169
  const className = this._commandLineArgs.apiClientName || 'ApiAutogeneratedService';
154
170
  const apiPre = this._getApiPre(className);
@@ -182,7 +198,7 @@ export abstract class ${className} {
182
198
  protected abstract _handleRequest<T>(request: T): T;
183
199
  protected abstract _handleMultipart<T>(request: T): FormData;
184
200
  protected abstract _handleResponse<T>(response: T): T;
185
- protected abstract _handleError(error: any, obs: any): Observable<never>;
201
+ protected abstract _handleError(error: any, obs: any, skipErrorHandling: boolean): Observable<never>;
186
202
  `;
187
203
  }
188
204
  }
@@ -1,28 +1,3 @@
1
- export const API_PRE =
2
- `import { HttpClient } from '@angular/common/http';
3
- import { Observable, catchError, map } from 'rxjs';
4
- import * as Models from './model.autogenerated';
5
- import { HttpHeaders } from "@angular/common/http";
6
-
7
- export const httpOptions = {
8
- headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
9
- };
10
-
11
- export const httpOptionsMultipart = {};
12
-
13
- export abstract class ApiAutogeneratedService {
14
- constructor(
15
- public _http: HttpClient,
16
- public _baseUrl: string,
17
- ) { }
18
-
19
- protected abstract _momentToString(moment: moment.Moment): string;
20
- protected abstract _handleRequest<T>(request: T): T;
21
- protected abstract _handleMultipart<T>(request: T): FormData;
22
- protected abstract _handleResponse<T>(response: T): T;
23
- protected abstract _handleError<T>(error: any, obs: Observable<T>, skipErrorHandling: boolean): Observable<never>;
24
- `;
25
-
26
1
  export const API_POST =
27
2
  `}`;
28
3