@devlearning/swagger-generator 1.0.3 → 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/README.md +205 -4
- package/autogeneration/output/api.autogenerated.ts +49 -1445
- package/autogeneration/output/model.autogenerated.ts +6 -2787
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +2 -2
- package/package.json +11 -5
- package/src/generator.ts +6 -6
- package/src/generators-writers/angular/api-angular-writer.ts +4 -2
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +2 -2
|
@@ -59,11 +59,11 @@ ${preparation}const response = await axios.${method}<${returnTypeString}>(\`${ap
|
|
|
59
59
|
_queryParametersPreparationStatement(parameter) {
|
|
60
60
|
if (parameter.nullable) {
|
|
61
61
|
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
62
|
-
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name}
|
|
62
|
+
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} !== undefined && isValid(${parameter.name}) ? encodeURIComponent(dateToZulu(${parameter.name})) : '';
|
|
63
63
|
`;
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name}
|
|
66
|
+
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} !== undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
67
67
|
`;
|
|
68
68
|
}
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devlearning/swagger-generator",
|
|
3
|
-
"version": "1.0.
|
|
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:
|
|
10
|
-
"debug-nextjs": "npx tsx src/index.ts http://localhost:
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -80,10 +80,10 @@ ${preparation}const response = await axios.${method}<${returnTypeString}>(\`${ap
|
|
|
80
80
|
private _queryParametersPreparationStatement(parameter: ParameterDto) {
|
|
81
81
|
if (parameter.nullable) {
|
|
82
82
|
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
83
|
-
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name}
|
|
83
|
+
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} !== undefined && isValid(${parameter.name}) ? encodeURIComponent(dateToZulu(${parameter.name})) : '';
|
|
84
84
|
`;
|
|
85
85
|
} else {
|
|
86
|
-
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name}
|
|
86
|
+
return ` const ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} !== undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
87
87
|
`;
|
|
88
88
|
}
|
|
89
89
|
} else {
|