@devlearning/swagger-generator 1.1.21 → 1.1.22
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/.vscode/launch.json +28 -28
- package/README-OLD.md +209 -209
- package/README.md +277 -277
- package/dist/api.constants.js +22 -22
- package/dist/generators-writers/angular/api-angular-writer.js +38 -38
- package/dist/generators-writers/angular/constants.js +24 -24
- package/dist/generators-writers/angular/model-angular-writer.js +6 -6
- package/dist/generators-writers/dart/model-dart-writer.js +11 -4
- package/dist/generators-writers/dart/templates/api.mustache +143 -143
- package/dist/generators-writers/dart/templates/enum.mustache +14 -14
- package/dist/generators-writers/dart/templates/model.mustache +23 -23
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +12 -12
- package/dist/generators-writers/nextjs/constants.js +4 -4
- package/dist/generators-writers/nextjs/model-nextjs-writer.js +6 -6
- package/dist/generators-writers/utils.d.ts +1 -0
- package/dist/generators-writers/utils.js +16 -4
- package/dist/templates/api.mustache +29 -0
- package/dist/templates/model.mustache +18 -0
- package/package.json +49 -49
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +752 -752
- package/src/generators-writers/angular/api-angular-writer.ts +187 -187
- package/src/generators-writers/angular/constants.ts +36 -36
- package/src/generators-writers/angular/model-angular-writer.ts +65 -65
- package/src/generators-writers/angular/normalizator.ts +41 -41
- package/src/generators-writers/dart/api-dart-writer.ts +303 -303
- package/src/generators-writers/dart/model-dart-writer.ts +226 -219
- package/src/generators-writers/dart/models/import-definition-dart.ts +5 -5
- package/src/generators-writers/dart/normalizator.ts +72 -72
- package/src/generators-writers/dart/templates/api.mustache +143 -143
- package/src/generators-writers/dart/templates/enum.mustache +14 -14
- package/src/generators-writers/dart/templates/model.mustache +23 -23
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +157 -157
- package/src/generators-writers/nextjs/constants.ts +5 -5
- package/src/generators-writers/nextjs/model-nextjs-writer.ts +61 -61
- package/src/generators-writers/utils.ts +111 -93
- package/src/index.ts +103 -103
- package/src/models/api-dto.ts +17 -17
- package/src/models/enum-value-dto.ts +3 -3
- package/src/models/model-dto.ts +9 -9
- package/src/models/parameter-dto.ts +7 -7
- package/src/models/property-dto.ts +4 -4
- package/src/models/swagger/swagger-component-property.ts +11 -11
- package/src/models/swagger/swagger-component.ts +17 -17
- package/src/models/swagger/swagger-content.ts +4 -4
- package/src/models/swagger/swagger-info.ts +3 -3
- package/src/models/swagger/swagger-method.ts +7 -7
- package/src/models/swagger/swagger-schema.ts +21 -21
- package/src/models/swagger/swagger.ts +38 -38
- package/src/models/type-dto.ts +7 -7
- package/src/swagger-downloader.ts +46 -46
- package/src/utils/logger.ts +73 -73
- package/src/utils/swagger-validator.ts +89 -89
- package/tsconfig.json +33 -33
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const API_PRE = `import axios from 'axios';
|
|
2
|
-
import * as Models from './model.autogenerated';
|
|
3
|
-
import { handleRequest, dateToZulu } from './utils/axios'
|
|
4
|
-
import { isValid } from 'date-fns';
|
|
1
|
+
export const API_PRE = `import axios from 'axios';
|
|
2
|
+
import * as Models from './model.autogenerated';
|
|
3
|
+
import { handleRequest, dateToZulu } from './utils/axios'
|
|
4
|
+
import { isValid } from 'date-fns';
|
|
5
5
|
`;
|
|
@@ -12,10 +12,10 @@ export class ModelNextJsWriter {
|
|
|
12
12
|
this._writeFile(modelString);
|
|
13
13
|
}
|
|
14
14
|
_modelString(model) {
|
|
15
|
-
let modelString = `
|
|
16
|
-
export ${model.modelType} ${model.name} {
|
|
17
|
-
${this._properties(model)}${this._enumValues(model)}
|
|
18
|
-
}
|
|
15
|
+
let modelString = `
|
|
16
|
+
export ${model.modelType} ${model.name} {
|
|
17
|
+
${this._properties(model)}${this._enumValues(model)}
|
|
18
|
+
}
|
|
19
19
|
`;
|
|
20
20
|
return modelString;
|
|
21
21
|
}
|
|
@@ -37,8 +37,8 @@ ${this._properties(model)}${this._enumValues(model)}
|
|
|
37
37
|
return enumValuesString.trimEnd();
|
|
38
38
|
}
|
|
39
39
|
_writeFile(models) {
|
|
40
|
-
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts", `
|
|
41
|
-
${models}
|
|
40
|
+
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts", `
|
|
41
|
+
${models}
|
|
42
42
|
`, { flag: 'w' });
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SwaggerSchema } from "../models/swagger/swagger-schema.js";
|
|
2
2
|
export declare class Utils {
|
|
3
|
+
private static _normalizeApiPathForMethodName;
|
|
3
4
|
static getNormalizedApiPathAngular(apiName: string): string;
|
|
4
5
|
static getNormalizedApiPathDart(apiName: string): string;
|
|
5
6
|
static toFirstLetterLowercase(value: string): string;
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
export class Utils {
|
|
4
|
+
static _normalizeApiPathForMethodName(apiName) {
|
|
5
|
+
let normalized = apiName ?? '';
|
|
6
|
+
// Remove placeholder segments (for example {id} or {version}).
|
|
7
|
+
normalized = normalized.replace(/\{[^}]+\}/g, '');
|
|
8
|
+
// Remove leading /api or api prefix.
|
|
9
|
+
normalized = normalized.replace(/^\/?api\/?/i, '');
|
|
10
|
+
// For paths like "repro/v1/..." remove both scope (repro) and version segment.
|
|
11
|
+
normalized = normalized.replace(/^[^/]+\/v\d*\//i, '');
|
|
12
|
+
// Remove version segment for paths without scope, like "v1/...".
|
|
13
|
+
normalized = normalized.replace(/\/?v\d*\//i, '/');
|
|
14
|
+
normalized = normalized.replace(/^\/+/, '');
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
4
17
|
static getNormalizedApiPathAngular(apiName) {
|
|
5
|
-
let normalizedApiName =
|
|
18
|
+
let normalizedApiName = this._normalizeApiPathForMethodName(apiName).replaceAll('/', '_');
|
|
6
19
|
if (normalizedApiName.charAt(0) == '_') {
|
|
7
20
|
normalizedApiName = normalizedApiName.slice(1);
|
|
8
21
|
}
|
|
9
22
|
normalizedApiName = normalizedApiName.replaceAll('/', '_');
|
|
23
|
+
normalizedApiName = normalizedApiName.replace(/^_+|_+$/g, '');
|
|
10
24
|
return normalizedApiName;
|
|
11
25
|
}
|
|
12
26
|
static getNormalizedApiPathDart(apiName) {
|
|
13
|
-
|
|
14
|
-
apiName = apiName.replace(/\{[^}]+\}/g, '');
|
|
15
|
-
let normalizedApiName = apiName.replace('/api/v{version}/', '').replaceAll('/', '_');
|
|
27
|
+
let normalizedApiName = this._normalizeApiPathForMethodName(apiName).replaceAll('/', '_');
|
|
16
28
|
if (normalizedApiName.charAt(0) == '_') {
|
|
17
29
|
normalizedApiName = normalizedApiName.slice(1);
|
|
18
30
|
}
|
|
@@ -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,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@devlearning/swagger-generator",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Swagger generator apis and models for Angular and NextJS",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "npx tsc && npm run copy-templates",
|
|
9
|
-
"debug-angular": "npx tsx src/index.ts --url http://localhost:
|
|
10
|
-
"debug-angular-unified": "npx tsx src/index.ts --url http://localhost:
|
|
11
|
-
"debug-nextjs": "npx tsx src/index.ts --url http://localhost:7550/swagger/ApiGateway/swagger.json --output autogen --target next --dateTimeLibrary date-fns",
|
|
12
|
-
"debug-flutter": "npx tsx src/index.ts --url http://localhost:7550/swagger/v1/swagger.json --output autogen --target flutter --package app",
|
|
13
|
-
"debug-flutter-unified": "npx tsx src/index.ts --url http://localhost:7550/swagger/v1/swagger.json --output autogen --target flutter --package app --api-client-name ApiClient",
|
|
14
|
-
"copy-templates": "copyfiles -u 3 \"src/generators-writers/dart/templates/**/*\" dist/generators-writers/dart",
|
|
15
|
-
"prepublishOnly": "npm run build",
|
|
16
|
-
"deploy": "npm publish"
|
|
17
|
-
},
|
|
18
|
-
"bin": {
|
|
19
|
-
"swgen": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [
|
|
22
|
-
"swagger",
|
|
23
|
-
"angular",
|
|
24
|
-
"nextjs",
|
|
25
|
-
"dart",
|
|
26
|
-
"flutter",
|
|
27
|
-
"api",
|
|
28
|
-
"generator"
|
|
29
|
-
],
|
|
30
|
-
"author": "",
|
|
31
|
-
"license": "ISC",
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"cli-progress": "^3.12.0",
|
|
34
|
-
"mustache": "^4.2.0",
|
|
35
|
-
"node-fetch": "^3.3.2",
|
|
36
|
-
"yargs": "^18.0.0"
|
|
37
|
-
},
|
|
38
|
-
"node-fetch": "^3.3.2",
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@types/cli-progress": "^3.11.6",
|
|
41
|
-
"@types/mustache": "^4.2.6",
|
|
42
|
-
"@types/node": "^24.7.0",
|
|
43
|
-
"@types/yargs": "^17.0.33",
|
|
44
|
-
"copyfiles": "^2.4.1",
|
|
45
|
-
"ts-node": "^10.9.1",
|
|
46
|
-
"tsconfig-paths": "^4.2.0",
|
|
47
|
-
"typescript": "^5.1.6"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@devlearning/swagger-generator",
|
|
3
|
+
"version": "1.1.22",
|
|
4
|
+
"description": "Swagger generator apis and models for Angular and NextJS",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npx tsc && npm run copy-templates",
|
|
9
|
+
"debug-angular": "npx tsx src/index.ts --url http://localhost:5289/swagger/repro-v1/swagger.json --output autogen --target angular --dateTimeLibrary moment",
|
|
10
|
+
"debug-angular-unified": "npx tsx src/index.ts --url http://localhost:5289/swagger/repro-v1/swagger.json --output autogen --target angular --dateTimeLibrary moment --api-client-name ApiClient",
|
|
11
|
+
"debug-nextjs": "npx tsx src/index.ts --url http://localhost:7550/swagger/ApiGateway/swagger.json --output autogen --target next --dateTimeLibrary date-fns",
|
|
12
|
+
"debug-flutter": "npx tsx src/index.ts --url http://localhost:7550/swagger/v1/swagger.json --output autogen --target flutter --package app",
|
|
13
|
+
"debug-flutter-unified": "npx tsx src/index.ts --url http://localhost:7550/swagger/v1/swagger.json --output autogen --target flutter --package app --api-client-name ApiClient",
|
|
14
|
+
"copy-templates": "copyfiles -u 3 \"src/generators-writers/dart/templates/**/*\" dist/generators-writers/dart",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"deploy": "npm publish"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"swgen": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"swagger",
|
|
23
|
+
"angular",
|
|
24
|
+
"nextjs",
|
|
25
|
+
"dart",
|
|
26
|
+
"flutter",
|
|
27
|
+
"api",
|
|
28
|
+
"generator"
|
|
29
|
+
],
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"cli-progress": "^3.12.0",
|
|
34
|
+
"mustache": "^4.2.0",
|
|
35
|
+
"node-fetch": "^3.3.2",
|
|
36
|
+
"yargs": "^18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"node-fetch": "^3.3.2",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/cli-progress": "^3.11.6",
|
|
41
|
+
"@types/mustache": "^4.2.6",
|
|
42
|
+
"@types/node": "^24.7.0",
|
|
43
|
+
"@types/yargs": "^17.0.33",
|
|
44
|
+
"copyfiles": "^2.4.1",
|
|
45
|
+
"ts-node": "^10.9.1",
|
|
46
|
+
"tsconfig-paths": "^4.2.0",
|
|
47
|
+
"typescript": "^5.1.6"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/api.constants.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export const API_PRE =
|
|
2
|
-
`import { HttpClient } from '@angular/common/http';
|
|
3
|
-
import { Observable, catchError, map } from 'rxjs';
|
|
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 = {};
|
|
12
|
-
|
|
13
|
-
export abstract class ApiAutogeneratedService {
|
|
14
|
-
constructor(
|
|
15
|
-
public _http: HttpClient,
|
|
16
|
-
public _baseUrl: string,
|
|
17
|
-
) { }
|
|
18
|
-
|
|
19
|
-
protected abstract _momentToString(moment: moment.Moment): string;
|
|
20
|
-
protected abstract _handleRequest<T>(request: T): T;
|
|
21
|
-
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
22
|
-
protected abstract _handleResponse<T>(response: T): T;
|
|
23
|
-
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
export const API_POST =
|
|
1
|
+
export const API_PRE =
|
|
2
|
+
`import { HttpClient } from '@angular/common/http';
|
|
3
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
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 = {};
|
|
12
|
+
|
|
13
|
+
export abstract class ApiAutogeneratedService {
|
|
14
|
+
constructor(
|
|
15
|
+
public _http: HttpClient,
|
|
16
|
+
public _baseUrl: string,
|
|
17
|
+
) { }
|
|
18
|
+
|
|
19
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
20
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
21
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
22
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
23
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const API_POST =
|
|
27
27
|
`}`;
|