@devlearning/swagger-generator 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "1.0.4",
4
- "description": "",
3
+ "version": "1.0.5",
4
+ "description": "Swagger generator apis and models for Angular and NextJS",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "dev": "ts-node --esm ./src/index.ts http://localhost:7550/swagger/ApiGateway/swagger.json autogeneration/output",
9
- "debug-angular": "npx tsx src/index.ts http://localhost:5208/swagger/v1/swagger.json autogeneration/output angular moment",
10
- "debug-nextjs": "npx tsx src/index.ts http://localhost:5208/swagger/v1/swagger.json autogeneration/output next date-fns",
9
+ "debug-angular": "npx tsx src/index.ts http://localhost:7550/swagger/ApiGateway/swagger.json autogeneration/output angular moment",
10
+ "debug-nextjs": "npx tsx src/index.ts http://localhost:7550/swagger/ApiGateway/swagger.json autogeneration/output next date-fns",
11
11
  "deploy": "npx tsc && npm publish"
12
12
  },
13
13
  "bin": {
14
14
  "swgen": "./dist/index.js"
15
15
  },
16
- "keywords": [],
16
+ "keywords": [
17
+ "swagger",
18
+ "angular",
19
+ "nextjs",
20
+ "api",
21
+ "generator"
22
+ ],
17
23
  "author": "",
18
24
  "license": "ISC",
19
25
  "dependencies": {
package/src/generator.ts CHANGED
@@ -67,7 +67,7 @@ export class Generator {
67
67
  this._barApis.start(Object.getOwnPropertyNames(this._swagger.paths).length, 0);
68
68
  for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
69
69
  const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
70
- this._barApis.update(index, { message: `Elaborando api... ${apiName}` });
70
+ this._barApis.update(index, { message: `Apis parsing... ${apiName}` });
71
71
  const apiSwaggerMethodKey = this._swagger.paths[apiName];
72
72
  const apiMethod = Object.getOwnPropertyNames(apiSwaggerMethodKey)[0];
73
73
  const apiSwaggerMethod = apiSwaggerMethodKey[apiMethod];
@@ -108,7 +108,7 @@ export class Generator {
108
108
  let parametersRefType = apiSwaggerMethod.parameters?.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''))
109
109
  if (parametersRefType) {
110
110
  usedTypes = usedTypes.concat(parametersRefType);
111
- this._barModels.update(index, { message: `Elaborando model... ${usedTypes}` });
111
+ this._barModels.update(index, { message: `Models parsing... ${usedTypes}` });
112
112
 
113
113
  if (apiSwaggerMethod.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
114
114
  usedTypes.push(apiSwaggerMethod.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
@@ -170,7 +170,7 @@ export class Generator {
170
170
  }
171
171
 
172
172
  generateApi() {
173
- this._barApis.update(this._apis.length, { message: `Inizio scrittura api...` });
173
+ this._barApis.update(this._apis.length, { message: `Api generating...` });
174
174
 
175
175
  if (this._outputFormat == 'angular') {
176
176
  const apiWriter = new ApiAngularWriter(this._outputDirectory);
@@ -180,14 +180,14 @@ export class Generator {
180
180
  apiWriter.write(this._apis);
181
181
  }
182
182
 
183
- this._barApis.update(this._apis.length, { message: `Scrittura api completata` });
183
+ this._barApis.update(this._apis.length, { message: `Api gerated` });
184
184
 
185
185
  this._barApis.stop();
186
186
  }
187
187
 
188
188
 
189
189
  generateModel() {
190
- this._barModels.update(this._apis.length, { message: `Inizio scrittura model...` });
190
+ this._barModels.update(this._apis.length, { message: `Model generation...` });
191
191
 
192
192
  if (this._outputFormat == 'angular') {
193
193
  const apiWriter = new ModelAngularWriter(this._outputDirectory);
@@ -197,7 +197,7 @@ export class Generator {
197
197
  apiWriter.write(this._models);
198
198
  }
199
199
 
200
- this._barModels.update(this._apis.length, { message: `Scrittura model completata` });
200
+ this._barModels.update(this._apis.length, { message: `Model generated` });
201
201
 
202
202
  this._barModels.stop();
203
203
  }
@@ -51,7 +51,8 @@ export class ApiAngularWriter {
51
51
  let parametersString = '';
52
52
 
53
53
  api.parameters.forEach(parameter => {
54
- parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${parameter.typeName}, `;
54
+ const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
55
+ parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${prefixType}${parameter.typeName}, `;
55
56
  });
56
57
 
57
58
  if (api.parameters.length > 0)
@@ -61,7 +62,8 @@ export class ApiAngularWriter {
61
62
  }
62
63
 
63
64
  private _returnType(api: ApiDto) {
64
- return api.returnType ? api.returnType.typeName : 'any';
65
+ const prefixType = !api.returnType?.isNativeType ? 'Models.' : '';
66
+ return api.returnType ? `${prefixType}${api.returnType.typeName}` : 'any';
65
67
  }
66
68
 
67
69
  private _queryParametersPreparation(api: ApiDto) {