@devlearning/swagger-generator 0.0.37 → 0.0.39
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/README.md +3 -1
- package/autogeneration/output/api.autogenerated.ts +2 -2
- package/dist/api.constants.js +7 -1
- package/dist/generator.js +9 -5
- package/package.json +1 -1
- package/src/api.constants.ts +7 -1
- package/src/generator.ts +11 -6
package/README.md
CHANGED
|
@@ -2,4 +2,6 @@ Add task on package.json
|
|
|
2
2
|
|
|
3
3
|
"swgen": "swgen http://localhost:5208/swagger/v1/swagger.json src/app/core/autogenerated"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
this generation work with momentjs
|
|
6
|
+
|
|
7
|
+
specify url of your swagger.json and path destination of generated files (in this example you must create path core/autogenerated)
|
|
@@ -16,7 +16,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
16
16
|
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
public
|
|
19
|
+
public catalog_Product(): Observable<string> {
|
|
20
20
|
return this._http.get<string>(`${this._baseUrl}/catalog/Product`, httpOptions)
|
|
21
21
|
.pipe(
|
|
22
22
|
map(x => this._handleResponse(x)),
|
|
@@ -24,7 +24,7 @@ export abstract class ApiAutogeneratedService {
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public
|
|
27
|
+
public tenant_Tenant(): Observable<string> {
|
|
28
28
|
return this._http.get<string>(`${this._baseUrl}/tenant/Tenant`, httpOptions)
|
|
29
29
|
.pipe(
|
|
30
30
|
map(x => this._handleResponse(x)),
|
package/dist/api.constants.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
2
|
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
-
import { httpOptions, httpOptionsMultipart } from 'src/app/core/utils/http-options';
|
|
4
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 = {};
|
|
5
11
|
|
|
6
12
|
export abstract class ApiAutogeneratedService {
|
|
7
13
|
constructor(
|
package/dist/generator.js
CHANGED
|
@@ -40,7 +40,7 @@ export class Generator {
|
|
|
40
40
|
}
|
|
41
41
|
apiMethods +=
|
|
42
42
|
`
|
|
43
|
-
public ${
|
|
43
|
+
public ${this.getApiNameNormalized(apiName)}(${parametersString}): Observable<${returnTypeString}> {
|
|
44
44
|
${queryParametersDeclaration}${prepareRequestString}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${apiName.replace('{version}', '1')}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
45
45
|
.pipe(
|
|
46
46
|
map(x => this._handleResponse(x)),
|
|
@@ -118,7 +118,7 @@ export ${type} ${modelName} {${content}
|
|
|
118
118
|
const method = Object.getOwnPropertyNames(swaggerMethod)[0];
|
|
119
119
|
const swaggerMethodInfo = swaggerMethod[method];
|
|
120
120
|
let type = 'class';
|
|
121
|
-
let modelName = this.
|
|
121
|
+
let modelName = this.getApiNameNormalized(apiName);
|
|
122
122
|
let content = this.retrieveSchemaProperties(swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData].schema);
|
|
123
123
|
models +=
|
|
124
124
|
`
|
|
@@ -132,7 +132,7 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
132
132
|
}
|
|
133
133
|
retrieveParameters(swaggerMethodInfo, apiName) {
|
|
134
134
|
if (swaggerMethodInfo.requestBody != null && swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData] != null) {
|
|
135
|
-
var modelName = this.
|
|
135
|
+
var modelName = this.getApiNameNormalized(apiName);
|
|
136
136
|
return `request: Models.${modelName}`;
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
@@ -378,8 +378,12 @@ ${MODEL_POST}`, { flag: 'w' });
|
|
|
378
378
|
throw new Error("unmanaged schema");
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
getApiNameNormalized(apiName) {
|
|
382
|
+
let normalizedApiName = apiName.replace('/api/v{version}/', '').replaceAll('/', '_');
|
|
383
|
+
if (normalizedApiName.charAt(0) == '_') {
|
|
384
|
+
normalizedApiName = normalizedApiName.slice(1);
|
|
385
|
+
}
|
|
386
|
+
return this.toFirstLetterLowercase(normalizedApiName);
|
|
383
387
|
}
|
|
384
388
|
toFirstLetterLowercase(value) {
|
|
385
389
|
return value.charAt(0).toLowerCase() + value.slice(1);
|
package/package.json
CHANGED
package/src/api.constants.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export const API_PRE =
|
|
2
2
|
`import { HttpClient } from '@angular/common/http';
|
|
3
3
|
import { Observable, catchError, map } from 'rxjs';
|
|
4
|
-
import { httpOptions, httpOptionsMultipart } from 'src/app/core/utils/http-options';
|
|
5
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 = {};
|
|
6
12
|
|
|
7
13
|
export abstract class ApiAutogeneratedService {
|
|
8
14
|
constructor(
|
package/src/generator.ts
CHANGED
|
@@ -51,7 +51,7 @@ export class Generator {
|
|
|
51
51
|
|
|
52
52
|
apiMethods +=
|
|
53
53
|
`
|
|
54
|
-
public ${
|
|
54
|
+
public ${this.getApiNameNormalized(apiName)}(${parametersString}): Observable<${returnTypeString}> {
|
|
55
55
|
${queryParametersDeclaration}${prepareRequestString}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${apiName.replace('{version}', '1')}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
56
56
|
.pipe(
|
|
57
57
|
map(x => this._handleResponse(x)),
|
|
@@ -143,7 +143,7 @@ export ${type} ${modelName} {${content}
|
|
|
143
143
|
}
|
|
144
144
|
`;
|
|
145
145
|
}
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
usedMultiPart.forEach(apiName => {
|
|
@@ -152,7 +152,7 @@ export ${type} ${modelName} {${content}
|
|
|
152
152
|
const swaggerMethodInfo = swaggerMethod[method];
|
|
153
153
|
|
|
154
154
|
let type = 'class';
|
|
155
|
-
let modelName = this.
|
|
155
|
+
let modelName = this.getApiNameNormalized(apiName);
|
|
156
156
|
let content = this.retrieveSchemaProperties(swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData].schema);
|
|
157
157
|
models +=
|
|
158
158
|
`
|
|
@@ -170,7 +170,7 @@ ${MODEL_POST}`,
|
|
|
170
170
|
|
|
171
171
|
retrieveParameters(swaggerMethodInfo: SwaggerMethod, apiName: string) {
|
|
172
172
|
if (swaggerMethodInfo.requestBody != null && swaggerMethodInfo.requestBody.content[contentTypeMultipartFormData] != null) {
|
|
173
|
-
var modelName = this.
|
|
173
|
+
var modelName = this.getApiNameNormalized(apiName);
|
|
174
174
|
return `request: Models.${modelName}`;
|
|
175
175
|
} else {
|
|
176
176
|
if (swaggerMethodInfo.requestBody != null) {
|
|
@@ -433,8 +433,13 @@ ${MODEL_POST}`,
|
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
|
|
437
|
-
|
|
436
|
+
getApiNameNormalized(apiName: string) {
|
|
437
|
+
let normalizedApiName = apiName.replace('/api/v{version}/', '').replaceAll('/', '_');
|
|
438
|
+
|
|
439
|
+
if (normalizedApiName.charAt(0) == '_') {
|
|
440
|
+
normalizedApiName = normalizedApiName.slice(1);
|
|
441
|
+
}
|
|
442
|
+
return this.toFirstLetterLowercase(normalizedApiName);
|
|
438
443
|
}
|
|
439
444
|
|
|
440
445
|
toFirstLetterLowercase(value: string) {
|