@devlearning/swagger-generator 1.0.13 → 1.0.16
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/dist/generator.js +2 -2
- package/dist/generators-writers/dart/api-dart-writer.js +3 -1
- package/dist/generators-writers/dart/model-dart-writer.js +2 -0
- package/dist/generators-writers/dart/templates/api.mustache +29 -0
- package/dist/generators-writers/dart/templates/model.mustache +18 -0
- package/dist/index.js +2 -2
- package/dist/templates/api.mustache +29 -0
- package/dist/templates/model.mustache +18 -0
- package/package.json +4 -2
- package/src/generator.ts +2 -2
- package/src/generators-writers/dart/api-dart-writer.ts +3 -2
- package/src/generators-writers/dart/model-dart-writer.ts +6 -4
- package/src/index.ts +2 -2
- package/dist/package.json +0 -37
- package/dist/src/api.constants.js +0 -24
- package/dist/src/generator-old.js +0 -369
- package/dist/src/generator.js +0 -425
- package/dist/src/generators-writers/angular/api-angular-writer.js +0 -113
- package/dist/src/generators-writers/angular/constants.js +0 -28
- package/dist/src/generators-writers/angular/model-angular-writer.js +0 -42
- package/dist/src/generators-writers/nextjs/api-nextjs-writer.js +0 -127
- package/dist/src/generators-writers/nextjs/constants.js +0 -5
- package/dist/src/generators-writers/nextjs/model-nextjs-writer.js +0 -41
- package/dist/src/generators-writers/utils.js +0 -20
- package/dist/src/index.js +0 -24
- package/dist/src/model.constants.js +0 -1
- package/dist/src/models/api-dto.js +0 -1
- package/dist/src/models/enum-value-dto.js +0 -1
- package/dist/src/models/model-dto.js +0 -1
- package/dist/src/models/parameter-dto.js +0 -1
- package/dist/src/models/property-dto.js +0 -1
- package/dist/src/models/swagger/swagger-component-property.js +0 -1
- package/dist/src/models/swagger/swagger-component.js +0 -1
- package/dist/src/models/swagger/swagger-content.js +0 -1
- package/dist/src/models/swagger/swagger-info.js +0 -1
- package/dist/src/models/swagger/swagger-method.js +0 -1
- package/dist/src/models/swagger/swagger-schema.js +0 -1
- package/dist/src/models/swagger/swagger.js +0 -1
- package/dist/src/models/type-dto.js +0 -1
- package/dist/src/swagger-downloader.js +0 -9
package/dist/generator.js
CHANGED
|
@@ -142,7 +142,7 @@ export class Generator {
|
|
|
142
142
|
const apiWriter = new ApiNextJsWriter(this._commandLineArgs.outputDirectory);
|
|
143
143
|
apiWriter.write(this._apis);
|
|
144
144
|
}
|
|
145
|
-
else if (this._commandLineArgs.target == TargetGeneration.
|
|
145
|
+
else if (this._commandLineArgs.target == TargetGeneration.Flutter) {
|
|
146
146
|
const apiWriter = new ApiDartWriter(this._commandLineArgs);
|
|
147
147
|
apiWriter.write(this._apis, this._models);
|
|
148
148
|
}
|
|
@@ -159,7 +159,7 @@ export class Generator {
|
|
|
159
159
|
const apiWriter = new ModelNextJsWriter(this._commandLineArgs.outputDirectory);
|
|
160
160
|
apiWriter.write(this._models);
|
|
161
161
|
}
|
|
162
|
-
else if (this._commandLineArgs.target == TargetGeneration.
|
|
162
|
+
else if (this._commandLineArgs.target == TargetGeneration.Flutter) {
|
|
163
163
|
const apiWriter = new ModelDartWriter(this._commandLineArgs);
|
|
164
164
|
apiWriter.write(this._models);
|
|
165
165
|
}
|
|
@@ -2,13 +2,15 @@ import fs, { writeFileSync } from 'fs';
|
|
|
2
2
|
import { Utils } from '../utils.js';
|
|
3
3
|
import * as Mustache from 'mustache';
|
|
4
4
|
import { Normalizator } from './normalizator.js';
|
|
5
|
+
import path from 'path';
|
|
5
6
|
export class ApiDartWriter {
|
|
6
7
|
_commandLineArgs;
|
|
7
8
|
constructor(commandLineArgs) {
|
|
8
9
|
this._commandLineArgs = commandLineArgs;
|
|
9
10
|
}
|
|
10
11
|
write(apis, models) {
|
|
11
|
-
const
|
|
12
|
+
const templatePath = path.join(__dirname, 'generators-writers', 'dart', 'templates', 'api.mustache');
|
|
13
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
12
14
|
const grouped = this._groupByTag(apis);
|
|
13
15
|
for (const [tag, apis] of Object.entries(grouped)) {
|
|
14
16
|
console.log(`Api: ${tag}`);
|
|
@@ -2,12 +2,14 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
2
2
|
import * as Mustache from 'mustache';
|
|
3
3
|
import { Utils } from '../utils.js';
|
|
4
4
|
import { Normalizator } from './normalizator.js';
|
|
5
|
+
import path from 'path';
|
|
5
6
|
export class ModelDartWriter {
|
|
6
7
|
_commandLineArgs;
|
|
7
8
|
constructor(commandLineArgs) {
|
|
8
9
|
this._commandLineArgs = commandLineArgs;
|
|
9
10
|
}
|
|
10
11
|
write(models) {
|
|
12
|
+
const templatePath = path.join(__dirname, 'generators-writers', 'dart', 'templates', 'model.mustache');
|
|
11
13
|
const template = readFileSync('src/generators-writers/dart/templates/model.mustache', 'utf-8');
|
|
12
14
|
models.forEach(model => {
|
|
13
15
|
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import 'package:{{package}}/core/di/injector.dart';
|
|
2
|
+
import 'package:dio/dio.dart';
|
|
3
|
+
{{#imports}}
|
|
4
|
+
{{{.}}}
|
|
5
|
+
{{/imports}}
|
|
6
|
+
|
|
7
|
+
class {{apiClassName}} {
|
|
8
|
+
final Dio _dio;
|
|
9
|
+
|
|
10
|
+
{{apiClassName}}() : _dio = getIt<Dio>();
|
|
11
|
+
|
|
12
|
+
{{#endpoints}}
|
|
13
|
+
Future<{{responseType}}> {{methodName}}({{#haveRequest}}{{requestType}} request{{/haveRequest}}) async {
|
|
14
|
+
final response = await _dio.{{httpMethod}}(
|
|
15
|
+
'{{{path}}}',
|
|
16
|
+
{{#haveRequest}}
|
|
17
|
+
{{#isGet}}
|
|
18
|
+
queryParameters: request.toJson(),
|
|
19
|
+
{{/isGet}}
|
|
20
|
+
{{^isGet}}
|
|
21
|
+
data: request.toJson(),
|
|
22
|
+
{{/isGet}}
|
|
23
|
+
{{/haveRequest}}
|
|
24
|
+
);
|
|
25
|
+
return {{responseType}}.fromJson(response.data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
{{/endpoints}}
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
{{#imports}}
|
|
3
|
+
{{{.}}}
|
|
4
|
+
{{/imports}}
|
|
5
|
+
|
|
6
|
+
part '{{filename}}.freezed.dart';
|
|
7
|
+
part '{{filename}}.g.dart';
|
|
8
|
+
|
|
9
|
+
@freezed
|
|
10
|
+
abstract class {{modelName}} with _${{modelName}} {
|
|
11
|
+
const factory {{modelName}}({
|
|
12
|
+
{{#fields}}
|
|
13
|
+
{{required}}{{type}}{{nullable}} {{name}},
|
|
14
|
+
{{/fields}}
|
|
15
|
+
}) = _{{modelName}};
|
|
16
|
+
|
|
17
|
+
factory {{modelName}}.fromJson(Map<String, dynamic> json) => _${{modelName}}FromJson(json);
|
|
18
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export var TargetGeneration;
|
|
|
12
12
|
(function (TargetGeneration) {
|
|
13
13
|
TargetGeneration["Angular"] = "angular";
|
|
14
14
|
TargetGeneration["Next"] = "next";
|
|
15
|
-
TargetGeneration["
|
|
15
|
+
TargetGeneration["Flutter"] = "flutter";
|
|
16
16
|
})(TargetGeneration || (TargetGeneration = {}));
|
|
17
17
|
const argv = yargs(hideBin(process.argv))
|
|
18
18
|
.scriptName("swagger-gen")
|
|
@@ -32,7 +32,7 @@ const argv = yargs(hideBin(process.argv))
|
|
|
32
32
|
.option('target', {
|
|
33
33
|
alias: 't',
|
|
34
34
|
type: 'string',
|
|
35
|
-
choices: ['angular', 'next', '
|
|
35
|
+
choices: ['angular', 'next', 'flutter'],
|
|
36
36
|
demandOption: true,
|
|
37
37
|
describe: 'Target format for the generated code',
|
|
38
38
|
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import 'package:{{package}}/core/di/injector.dart';
|
|
2
|
+
import 'package:dio/dio.dart';
|
|
3
|
+
{{#imports}}
|
|
4
|
+
{{{.}}}
|
|
5
|
+
{{/imports}}
|
|
6
|
+
|
|
7
|
+
class {{apiClassName}} {
|
|
8
|
+
final Dio _dio;
|
|
9
|
+
|
|
10
|
+
{{apiClassName}}() : _dio = getIt<Dio>();
|
|
11
|
+
|
|
12
|
+
{{#endpoints}}
|
|
13
|
+
Future<{{responseType}}> {{methodName}}({{#haveRequest}}{{requestType}} request{{/haveRequest}}) async {
|
|
14
|
+
final response = await _dio.{{httpMethod}}(
|
|
15
|
+
'{{{path}}}',
|
|
16
|
+
{{#haveRequest}}
|
|
17
|
+
{{#isGet}}
|
|
18
|
+
queryParameters: request.toJson(),
|
|
19
|
+
{{/isGet}}
|
|
20
|
+
{{^isGet}}
|
|
21
|
+
data: request.toJson(),
|
|
22
|
+
{{/isGet}}
|
|
23
|
+
{{/haveRequest}}
|
|
24
|
+
);
|
|
25
|
+
return {{responseType}}.fromJson(response.data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
{{/endpoints}}
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
{{#imports}}
|
|
3
|
+
{{{.}}}
|
|
4
|
+
{{/imports}}
|
|
5
|
+
|
|
6
|
+
part '{{filename}}.freezed.dart';
|
|
7
|
+
part '{{filename}}.g.dart';
|
|
8
|
+
|
|
9
|
+
@freezed
|
|
10
|
+
abstract class {{modelName}} with _${{modelName}} {
|
|
11
|
+
const factory {{modelName}}({
|
|
12
|
+
{{#fields}}
|
|
13
|
+
{{required}}{{type}}{{nullable}} {{name}},
|
|
14
|
+
{{/fields}}
|
|
15
|
+
}) = _{{modelName}};
|
|
16
|
+
|
|
17
|
+
factory {{modelName}}.fromJson(Map<String, dynamic> json) => _${{modelName}}FromJson(json);
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devlearning/swagger-generator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Swagger generator apis and models for Angular and NextJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"debug-angular": "npx tsx src/index.ts --url http://localhost:7550/swagger/ApiGateway/swagger.json --output autogeneration/output --target angular --dateTimeLibrary moment",
|
|
9
9
|
"debug-nextjs": "npx tsx src/index.ts --url http://localhost:7550/swagger/ApiGateway/swagger.json --output autogeneration/output --target next --dateTimeLibrary date-fns",
|
|
10
10
|
"debug-flutter": "npx tsx src/index.ts --url http://localhost:7550/swagger/ApiGateway/swagger.json --output autogen --target flutter --package coqudo_app",
|
|
11
|
-
"
|
|
11
|
+
"copy-templates": "copyfiles -u 3 \"src/generators-writers/dart/templates/**/*\" dist/generators-writers/dart",
|
|
12
|
+
"deploy": "npx tsc & copyfiles & npm publish"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|
|
14
15
|
"swgen": "./dist/index.js"
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"@types/mustache": "^4.2.6",
|
|
37
38
|
"@types/node": "^18.15.0",
|
|
38
39
|
"@types/yargs": "^17.0.33",
|
|
40
|
+
"copyfiles": "^2.4.1",
|
|
39
41
|
"ts-node": "^10.9.1",
|
|
40
42
|
"tsconfig-paths": "^4.2.0",
|
|
41
43
|
"typescript": "^5.1.6"
|
package/src/generator.ts
CHANGED
|
@@ -185,7 +185,7 @@ export class Generator {
|
|
|
185
185
|
} else if (this._commandLineArgs.target == TargetGeneration.Next) {
|
|
186
186
|
const apiWriter = new ApiNextJsWriter(this._commandLineArgs.outputDirectory);
|
|
187
187
|
apiWriter.write(this._apis);
|
|
188
|
-
} else if (this._commandLineArgs.target == TargetGeneration.
|
|
188
|
+
} else if (this._commandLineArgs.target == TargetGeneration.Flutter) {
|
|
189
189
|
const apiWriter = new ApiDartWriter(this._commandLineArgs);
|
|
190
190
|
apiWriter.write(this._apis, this._models);
|
|
191
191
|
}
|
|
@@ -205,7 +205,7 @@ export class Generator {
|
|
|
205
205
|
} else if (this._commandLineArgs.target == TargetGeneration.Next) {
|
|
206
206
|
const apiWriter = new ModelNextJsWriter(this._commandLineArgs.outputDirectory);
|
|
207
207
|
apiWriter.write(this._models);
|
|
208
|
-
} else if (this._commandLineArgs.target == TargetGeneration.
|
|
208
|
+
} else if (this._commandLineArgs.target == TargetGeneration.Flutter) {
|
|
209
209
|
const apiWriter = new ModelDartWriter(this._commandLineArgs);
|
|
210
210
|
apiWriter.write(this._models);
|
|
211
211
|
}
|
|
@@ -8,6 +8,7 @@ import { ModelDto } from '@src/models/model-dto.js';
|
|
|
8
8
|
import { TypeDto } from '@src/models/type-dto.js';
|
|
9
9
|
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
10
10
|
import { Normalizator } from './normalizator.js';
|
|
11
|
+
import path from 'path';
|
|
11
12
|
|
|
12
13
|
interface ApiDefinitionDart {
|
|
13
14
|
package: string;
|
|
@@ -39,8 +40,8 @@ export class ApiDartWriter {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
write(apis: ApiDto[], models: ModelDto[]) {
|
|
42
|
-
|
|
43
|
-
const template = fs.readFileSync(
|
|
43
|
+
const templatePath = path.join(__dirname, 'generators-writers', 'dart', 'templates', 'api.mustache');
|
|
44
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
44
45
|
|
|
45
46
|
const grouped = this._groupByTag(apis);
|
|
46
47
|
|
|
@@ -5,6 +5,7 @@ import { Utils } from '../utils.js';
|
|
|
5
5
|
import { CommandLineArgs } from '@src/index.js';
|
|
6
6
|
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
7
7
|
import { Normalizator } from './normalizator.js';
|
|
8
|
+
import path from 'path';
|
|
8
9
|
|
|
9
10
|
interface ModelDefinitionDart {
|
|
10
11
|
modelName?: string;
|
|
@@ -36,6 +37,7 @@ export class ModelDartWriter {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
write(models: ModelDto[]) {
|
|
40
|
+
const templatePath = path.join(__dirname, 'generators-writers', 'dart', 'templates', 'model.mustache');
|
|
39
41
|
const template = readFileSync('src/generators-writers/dart/templates/model.mustache', 'utf-8');
|
|
40
42
|
|
|
41
43
|
models.forEach(model => {
|
|
@@ -47,15 +49,15 @@ export class ModelDartWriter {
|
|
|
47
49
|
fields: [],
|
|
48
50
|
imports: [],
|
|
49
51
|
};
|
|
50
|
-
|
|
52
|
+
|
|
51
53
|
var imports = <ImportDefinitionDart[]>[];
|
|
52
54
|
|
|
53
55
|
model.properties.forEach(property => {
|
|
54
56
|
var fieldTypeName = this._mapTsTypeToDart(property.typeName);
|
|
55
57
|
|
|
56
|
-
// if (fieldTypeName.endsWith('Exception')) {
|
|
57
|
-
// debugger
|
|
58
|
-
// }
|
|
58
|
+
// if (fieldTypeName.endsWith('Exception')) {
|
|
59
|
+
// debugger
|
|
60
|
+
// }
|
|
59
61
|
|
|
60
62
|
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
61
63
|
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export enum DateTimeLibrary {
|
|
|
13
13
|
export enum TargetGeneration {
|
|
14
14
|
Angular = 'angular',
|
|
15
15
|
Next = 'next',
|
|
16
|
-
|
|
16
|
+
Flutter = 'flutter',
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface CommandLineArgs {
|
|
@@ -42,7 +42,7 @@ const argv = yargs(hideBin(process.argv))
|
|
|
42
42
|
.option('target', {
|
|
43
43
|
alias: 't',
|
|
44
44
|
type: 'string',
|
|
45
|
-
choices: ['angular', 'next', '
|
|
45
|
+
choices: ['angular', 'next', 'flutter'],
|
|
46
46
|
demandOption: true,
|
|
47
47
|
describe: 'Target format for the generated code',
|
|
48
48
|
})
|
package/dist/package.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@devlearning/swagger-generator",
|
|
3
|
-
"version": "1.0.9",
|
|
4
|
-
"description": "Swagger generator apis and models for Angular and NextJS",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
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: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
|
-
"deploy": "npx tsc && npm publish"
|
|
12
|
-
},
|
|
13
|
-
"bin": {
|
|
14
|
-
"swgen": "./dist/index.js"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"swagger",
|
|
18
|
-
"angular",
|
|
19
|
-
"nextjs",
|
|
20
|
-
"api",
|
|
21
|
-
"generator"
|
|
22
|
-
],
|
|
23
|
-
"author": "",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"cli-progress": "^3.12.0",
|
|
27
|
-
"node-fetch": "^3.3.2"
|
|
28
|
-
},
|
|
29
|
-
"node-fetch": "^3.3.2",
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@types/cli-progress": "^3.11.6",
|
|
32
|
-
"@types/node": "^18.15.0",
|
|
33
|
-
"ts-node": "^10.9.1",
|
|
34
|
-
"tsconfig-paths": "^4.2.0",
|
|
35
|
-
"typescript": "^5.1.6"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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(error: any, obs: any): Observable<never>;
|
|
23
|
-
`;
|
|
24
|
-
export const API_POST = `}`;
|