@devlearning/swagger-generator 1.0.8 → 1.0.10

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.
@@ -0,0 +1,50 @@
1
+ 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(error: any, obs: any): Observable<never>;
23
+
24
+
25
+ public catalog_Product_Read(idProduct?: number): Observable<Models.Product> {
26
+ let idProductParam: string = idProduct != null && idProduct != undefined ? encodeURIComponent('' + idProduct) : '';
27
+ return this._http.get<Models.Product>(`${this._baseUrl}/catalog/Product/Read?idProduct=${idProductParam}`, httpOptions)
28
+ .pipe(
29
+ map(x => this._handleResponse(x)),
30
+ catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
31
+ );
32
+ }
33
+
34
+ public catalog_Product_List(): Observable<Models.Product[]> {
35
+ return this._http.get<Models.Product[]>(`${this._baseUrl}/catalog/Product/List`, httpOptions)
36
+ .pipe(
37
+ map(x => this._handleResponse(x)),
38
+ catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
39
+ );
40
+ }
41
+
42
+ public tenant_Tenant(): Observable<string> {
43
+ return this._http.get<string>(`${this._baseUrl}/tenant/Tenant`, httpOptions)
44
+ .pipe(
45
+ map(x => this._handleResponse(x)),
46
+ catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
47
+ );
48
+ }
49
+
50
+ }
@@ -0,0 +1,10 @@
1
+ import * as moment from 'moment';
2
+
3
+
4
+ export class Product {
5
+ idProduct?: string;
6
+ name?: string;
7
+ quantity?: number;
8
+ }
9
+
10
+
package/dist/generator.js CHANGED
@@ -44,7 +44,7 @@ export class Generator {
44
44
  this._barApis.start(Object.getOwnPropertyNames(this._swagger.paths).length, 0);
45
45
  for (let index = 0; index < Object.getOwnPropertyNames(this._swagger.paths).length; index++) {
46
46
  const apiName = Object.getOwnPropertyNames(this._swagger.paths)[index];
47
- this._barApis.update(index, { message: `Elaborando api... ${apiName}` });
47
+ this._barApis.update(index, { message: `Apis parsing... ${apiName}` });
48
48
  const apiSwaggerMethodKey = this._swagger.paths[apiName];
49
49
  const apiMethod = Object.getOwnPropertyNames(apiSwaggerMethodKey)[0];
50
50
  const apiSwaggerMethod = apiSwaggerMethodKey[apiMethod];
@@ -78,7 +78,7 @@ export class Generator {
78
78
  let parametersRefType = apiSwaggerMethod.parameters?.filter(x => x.in == 'query' && x.schema?.$ref != null).map(x => x.schema.$ref.replace('#/components/schemas/', ''));
79
79
  if (parametersRefType) {
80
80
  usedTypes = usedTypes.concat(parametersRefType);
81
- this._barModels.update(index, { message: `Elaborando model... ${usedTypes}` });
81
+ this._barModels.update(index, { message: `Models parsing... ${usedTypes}` });
82
82
  if (apiSwaggerMethod.responses[200].content[contentTypeApplicationJson]?.schema.$ref != null) {
83
83
  usedTypes.push(apiSwaggerMethod.responses[200].content[contentTypeApplicationJson].schema.$ref.replace('#/components/schemas/', ''));
84
84
  }
@@ -127,7 +127,7 @@ export class Generator {
127
127
  });
128
128
  }
129
129
  generateApi() {
130
- this._barApis.update(this._apis.length, { message: `Inizio scrittura api...` });
130
+ this._barApis.update(this._apis.length, { message: `Api generating...` });
131
131
  if (this._outputFormat == 'angular') {
132
132
  const apiWriter = new ApiAngularWriter(this._outputDirectory);
133
133
  apiWriter.write(this._apis);
@@ -136,11 +136,11 @@ export class Generator {
136
136
  const apiWriter = new ApiNextJsWriter(this._outputDirectory);
137
137
  apiWriter.write(this._apis);
138
138
  }
139
- this._barApis.update(this._apis.length, { message: `Scrittura api completata` });
139
+ this._barApis.update(this._apis.length, { message: `Api gerated` });
140
140
  this._barApis.stop();
141
141
  }
142
142
  generateModel() {
143
- this._barModels.update(this._apis.length, { message: `Inizio scrittura model...` });
143
+ this._barModels.update(this._apis.length, { message: `Model generation...` });
144
144
  if (this._outputFormat == 'angular') {
145
145
  const apiWriter = new ModelAngularWriter(this._outputDirectory);
146
146
  apiWriter.write(this._models);
@@ -149,7 +149,7 @@ export class Generator {
149
149
  const apiWriter = new ModelNextJsWriter(this._outputDirectory);
150
150
  apiWriter.write(this._models);
151
151
  }
152
- this._barModels.update(this._apis.length, { message: `Scrittura model completata` });
152
+ this._barModels.update(this._apis.length, { message: `Model generated` });
153
153
  this._barModels.stop();
154
154
  }
155
155
  computeParameters(apiName, swaggerMethod) {
@@ -37,14 +37,16 @@ export class ApiAngularWriter {
37
37
  _parameters(api) {
38
38
  let parametersString = '';
39
39
  api.parameters.forEach(parameter => {
40
- parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${parameter.typeName}, `;
40
+ const prefixType = parameter.isEnum || !parameter.isNativeType ? 'Models.' : '';
41
+ parametersString += `${parameter.name}${parameter.nullable ? '?' : ''}: ${prefixType}${parameter.typeName}, `;
41
42
  });
42
43
  if (api.parameters.length > 0)
43
44
  parametersString = parametersString.substring(0, parametersString.length - 2);
44
45
  return parametersString;
45
46
  }
46
47
  _returnType(api) {
47
- return api.returnType ? api.returnType.typeName : 'any';
48
+ const prefixType = !api.returnType?.isNativeType ? 'Models.' : '';
49
+ return api.returnType ? `${prefixType}${api.returnType.typeName}` : 'any';
48
50
  }
49
51
  _queryParametersPreparation(api) {
50
52
  let queryParametersPreparation = '';
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Swagger generator apis and models for Angular and NextJS",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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
@@ -15,7 +15,6 @@ import { ModelNextJsWriter } from './generators-writers/nextjs/model-nextjs-writ
15
15
  import { ModelAngularWriter } from './generators-writers/angular/model-angular-writer.js';
16
16
  import { PropertyDto } from './models/property-dto.js';
17
17
  import { EnumValueDto } from './models/enum-value-dto.js';
18
- import pkg from '../package.json' assert { type: 'json' };
19
18
 
20
19
  const contentTypeApplicationJson = 'application/json';
21
20
  const contentTypeMultipartFormData = 'multipart/form-data';
@@ -53,8 +52,6 @@ export class Generator {
53
52
  }
54
53
 
55
54
  generate() {
56
- console.info(`%c[Swagger API Generator] Version ${pkg.version}`, 'color: #4CAF50; font-weight: bold;');
57
-
58
55
  console.info('%c[Swagger API Generator] %cStarting to parse Swagger JSON file...', 'color: #4CAF50; font-weight: bold;', 'color: #2196F3;');
59
56
 
60
57
  this.computeApi();
package/tsconfig.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "module": "NodeNext",
4
+ "module": "ES2022",
5
5
  "baseUrl": "./src",
6
6
  "moduleResolution": "NodeNext",
7
- "resolveJsonModule": true,
8
7
  "paths": {
9
8
  "@src/*": [
10
9
  "*"
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};