@devlearning/swagger-generator 1.1.0 → 1.1.1
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.md +209 -209
- package/dist/api.constants.js +22 -22
- package/dist/generators-writers/angular/api-angular-writer.js +15 -15
- 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/api-dart-writer.js +8 -2
- package/dist/generators-writers/dart/templates/api.mustache +49 -36
- package/dist/generators-writers/dart/templates/enum.mustache +14 -14
- package/dist/generators-writers/dart/templates/model.mustache +17 -17
- 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/package.json +45 -45
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +582 -582
- package/src/generators-writers/angular/api-angular-writer.ts +141 -141
- package/src/generators-writers/angular/constants.ts +36 -36
- package/src/generators-writers/angular/model-angular-writer.ts +62 -62
- package/src/generators-writers/dart/api-dart-writer.ts +198 -190
- package/src/generators-writers/dart/model-dart-writer.ts +162 -162
- 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 +49 -36
- package/src/generators-writers/dart/templates/enum.mustache +14 -14
- package/src/generators-writers/dart/templates/model.mustache +17 -17
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +156 -156
- 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 +78 -78
- package/src/index.ts +96 -96
- 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 +20 -20
- package/src/models/swagger/swagger.ts +38 -38
- package/src/models/type-dto.ts +7 -7
- package/src/swagger-downloader.ts +12 -12
- package/tsconfig.json +28 -28
- package/dist/models/swagger-component-property.js +0 -1
- package/dist/models/swagger-component.js +0 -1
- package/dist/models/swagger-content.js +0 -1
- package/dist/models/swagger-info.js +0 -1
- package/dist/models/swagger-method.js +0 -1
- package/dist/models/swagger-schema.js +0 -1
- package/dist/models/swagger.js +0 -1
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
import fs, { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { ModelDto } from '@src/models/model-dto.js';
|
|
3
|
-
import * as Mustache from 'mustache';
|
|
4
|
-
import { Utils } from '../utils.js';
|
|
5
|
-
import { CommandLineArgs } from '@src/index.js';
|
|
6
|
-
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
7
|
-
import { Normalizator } from './normalizator.js';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
|
|
11
|
-
interface ClassDefinitionDart {
|
|
12
|
-
className?: string;
|
|
13
|
-
fields?: { name: string; type: string }[];
|
|
14
|
-
imports?: string[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface EnumDefinitionDart {
|
|
18
|
-
enumName?: string;
|
|
19
|
-
fields?: EnumItemDefinitionDart[];
|
|
20
|
-
imports?: string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface EnumItemDefinitionDart {
|
|
24
|
-
name: string;
|
|
25
|
-
value: string;
|
|
26
|
-
isLast: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface FieldDefinitionDart {
|
|
30
|
-
name: string;
|
|
31
|
-
type: string;
|
|
32
|
-
typeName: string;
|
|
33
|
-
nullable: string;
|
|
34
|
-
required: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ExportClassDefinitionDart {
|
|
38
|
-
classes: ClassDefinitionDart[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ExportEnumDefinitionDart {
|
|
42
|
-
classes: EnumDefinitionDart[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface ExportModelItemDefinitionDart {
|
|
46
|
-
filename?: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class ModelDartWriter {
|
|
50
|
-
private _commandLineArgs: CommandLineArgs;
|
|
51
|
-
|
|
52
|
-
constructor(commandLineArgs: CommandLineArgs) {
|
|
53
|
-
this._commandLineArgs = commandLineArgs;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
write(models: ModelDto[]) {
|
|
57
|
-
this.writeEnums(models.filter(m => m.modelType === 'enum'));
|
|
58
|
-
this.writeClasses(models);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
writeClasses(models: ModelDto[]) {
|
|
62
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
63
|
-
const __dirname = path.dirname(__filename);
|
|
64
|
-
const templatePath = path.join(__dirname, 'templates', 'model.mustache');
|
|
65
|
-
const template = readFileSync(templatePath, 'utf-8');
|
|
66
|
-
|
|
67
|
-
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
68
|
-
if (importDirectory.startsWith('lib/')) {
|
|
69
|
-
importDirectory = importDirectory.slice('lib/'.length);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
models.forEach(model => {
|
|
73
|
-
if (model.modelType === 'class' || model.modelType === 'interface') {
|
|
74
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
75
|
-
const dartModel = <ClassDefinitionDart>{
|
|
76
|
-
filename: normalizedInfo.filename,
|
|
77
|
-
path: this._commandLineArgs.outputDirectory,
|
|
78
|
-
className: normalizedInfo.modelName,
|
|
79
|
-
fields: [],
|
|
80
|
-
imports: [],
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
var imports = <ImportDefinitionDart[]>[];
|
|
84
|
-
|
|
85
|
-
model.properties.forEach(property => {
|
|
86
|
-
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
87
|
-
|
|
88
|
-
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
89
|
-
|
|
90
|
-
dartModel.fields!.push(<FieldDefinitionDart>{
|
|
91
|
-
name: property.name,
|
|
92
|
-
type: property.isArray ? `List<${fieldTypeName}>` : fieldTypeName,
|
|
93
|
-
typeName: property.typeName,
|
|
94
|
-
nullable: property.nullable && !property.isArray ? '?' : '',
|
|
95
|
-
required: property.nullable && !property.isArray ? '' : 'required ',
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
if (property.isTypeReference) {
|
|
99
|
-
if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
|
|
100
|
-
models.forEach(currModel => {
|
|
101
|
-
if (currModel.typeName === property.typeName) {
|
|
102
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(currModel);
|
|
103
|
-
imports.push({
|
|
104
|
-
type: property,
|
|
105
|
-
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
dartModel.imports = imports.map(i => i.import);
|
|
114
|
-
|
|
115
|
-
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
116
|
-
|
|
117
|
-
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
118
|
-
|
|
119
|
-
let result = Mustache.default.render(template, dartModel);
|
|
120
|
-
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
writeEnums(models: ModelDto[]) {
|
|
126
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
127
|
-
const __dirname = path.dirname(__filename);
|
|
128
|
-
const templatePath = path.join(__dirname, 'templates', 'enum.mustache');
|
|
129
|
-
const template = readFileSync(templatePath, 'utf-8');
|
|
130
|
-
|
|
131
|
-
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
132
|
-
if (importDirectory.startsWith('lib/')) {
|
|
133
|
-
importDirectory = importDirectory.slice('lib/'.length);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
models.forEach(model => {
|
|
137
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
138
|
-
const dartModel = <EnumDefinitionDart>{
|
|
139
|
-
enumName: normalizedInfo.modelName,
|
|
140
|
-
path: this._commandLineArgs.outputDirectory,
|
|
141
|
-
fields: [],
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
model.enumValues.forEach(enumItem => {
|
|
145
|
-
dartModel.fields!.push(<EnumItemDefinitionDart>{
|
|
146
|
-
name: enumItem.name,
|
|
147
|
-
value: enumItem.value,
|
|
148
|
-
isLast: false,
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const lastIndex = dartModel.fields!.length - 1;
|
|
153
|
-
dartModel.fields![lastIndex].isLast = true;
|
|
154
|
-
|
|
155
|
-
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
156
|
-
|
|
157
|
-
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
158
|
-
|
|
159
|
-
let result = Mustache.default.render(template, dartModel);
|
|
160
|
-
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
161
|
-
});
|
|
162
|
-
}
|
|
1
|
+
import fs, { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { ModelDto } from '@src/models/model-dto.js';
|
|
3
|
+
import * as Mustache from 'mustache';
|
|
4
|
+
import { Utils } from '../utils.js';
|
|
5
|
+
import { CommandLineArgs } from '@src/index.js';
|
|
6
|
+
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
7
|
+
import { Normalizator } from './normalizator.js';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
interface ClassDefinitionDart {
|
|
12
|
+
className?: string;
|
|
13
|
+
fields?: { name: string; type: string }[];
|
|
14
|
+
imports?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface EnumDefinitionDart {
|
|
18
|
+
enumName?: string;
|
|
19
|
+
fields?: EnumItemDefinitionDart[];
|
|
20
|
+
imports?: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface EnumItemDefinitionDart {
|
|
24
|
+
name: string;
|
|
25
|
+
value: string;
|
|
26
|
+
isLast: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface FieldDefinitionDart {
|
|
30
|
+
name: string;
|
|
31
|
+
type: string;
|
|
32
|
+
typeName: string;
|
|
33
|
+
nullable: string;
|
|
34
|
+
required: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ExportClassDefinitionDart {
|
|
38
|
+
classes: ClassDefinitionDart[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ExportEnumDefinitionDart {
|
|
42
|
+
classes: EnumDefinitionDart[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ExportModelItemDefinitionDart {
|
|
46
|
+
filename?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ModelDartWriter {
|
|
50
|
+
private _commandLineArgs: CommandLineArgs;
|
|
51
|
+
|
|
52
|
+
constructor(commandLineArgs: CommandLineArgs) {
|
|
53
|
+
this._commandLineArgs = commandLineArgs;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
write(models: ModelDto[]) {
|
|
57
|
+
this.writeEnums(models.filter(m => m.modelType === 'enum'));
|
|
58
|
+
this.writeClasses(models);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
writeClasses(models: ModelDto[]) {
|
|
62
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
63
|
+
const __dirname = path.dirname(__filename);
|
|
64
|
+
const templatePath = path.join(__dirname, 'templates', 'model.mustache');
|
|
65
|
+
const template = readFileSync(templatePath, 'utf-8');
|
|
66
|
+
|
|
67
|
+
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
68
|
+
if (importDirectory.startsWith('lib/')) {
|
|
69
|
+
importDirectory = importDirectory.slice('lib/'.length);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
models.forEach(model => {
|
|
73
|
+
if (model.modelType === 'class' || model.modelType === 'interface') {
|
|
74
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
75
|
+
const dartModel = <ClassDefinitionDart>{
|
|
76
|
+
filename: normalizedInfo.filename,
|
|
77
|
+
path: this._commandLineArgs.outputDirectory,
|
|
78
|
+
className: normalizedInfo.modelName,
|
|
79
|
+
fields: [],
|
|
80
|
+
imports: [],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
var imports = <ImportDefinitionDart[]>[];
|
|
84
|
+
|
|
85
|
+
model.properties.forEach(property => {
|
|
86
|
+
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
87
|
+
|
|
88
|
+
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
89
|
+
|
|
90
|
+
dartModel.fields!.push(<FieldDefinitionDart>{
|
|
91
|
+
name: property.name,
|
|
92
|
+
type: property.isArray ? `List<${fieldTypeName}>` : fieldTypeName,
|
|
93
|
+
typeName: property.typeName,
|
|
94
|
+
nullable: property.nullable && !property.isArray ? '?' : '',
|
|
95
|
+
required: property.nullable && !property.isArray ? '' : 'required ',
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (property.isTypeReference) {
|
|
99
|
+
if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
|
|
100
|
+
models.forEach(currModel => {
|
|
101
|
+
if (currModel.typeName === property.typeName) {
|
|
102
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(currModel);
|
|
103
|
+
imports.push({
|
|
104
|
+
type: property,
|
|
105
|
+
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
dartModel.imports = imports.map(i => i.import);
|
|
114
|
+
|
|
115
|
+
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
116
|
+
|
|
117
|
+
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
118
|
+
|
|
119
|
+
let result = Mustache.default.render(template, dartModel);
|
|
120
|
+
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
writeEnums(models: ModelDto[]) {
|
|
126
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
127
|
+
const __dirname = path.dirname(__filename);
|
|
128
|
+
const templatePath = path.join(__dirname, 'templates', 'enum.mustache');
|
|
129
|
+
const template = readFileSync(templatePath, 'utf-8');
|
|
130
|
+
|
|
131
|
+
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
132
|
+
if (importDirectory.startsWith('lib/')) {
|
|
133
|
+
importDirectory = importDirectory.slice('lib/'.length);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
models.forEach(model => {
|
|
137
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
138
|
+
const dartModel = <EnumDefinitionDart>{
|
|
139
|
+
enumName: normalizedInfo.modelName,
|
|
140
|
+
path: this._commandLineArgs.outputDirectory,
|
|
141
|
+
fields: [],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
model.enumValues.forEach(enumItem => {
|
|
145
|
+
dartModel.fields!.push(<EnumItemDefinitionDart>{
|
|
146
|
+
name: enumItem.name,
|
|
147
|
+
value: enumItem.value,
|
|
148
|
+
isLast: false,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const lastIndex = dartModel.fields!.length - 1;
|
|
153
|
+
dartModel.fields![lastIndex].isLast = true;
|
|
154
|
+
|
|
155
|
+
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
156
|
+
|
|
157
|
+
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
158
|
+
|
|
159
|
+
let result = Mustache.default.render(template, dartModel);
|
|
160
|
+
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
163
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TypeDto } from "@src/models/type-dto.js";
|
|
2
|
-
|
|
3
|
-
export interface ImportDefinitionDart {
|
|
4
|
-
type: TypeDto;
|
|
5
|
-
import: string
|
|
1
|
+
import { TypeDto } from "@src/models/type-dto.js";
|
|
2
|
+
|
|
3
|
+
export interface ImportDefinitionDart {
|
|
4
|
+
type: TypeDto;
|
|
5
|
+
import: string
|
|
6
6
|
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { ModelDto } from "@src/models/model-dto.js";
|
|
2
|
-
import { Utils } from "../utils.js";
|
|
3
|
-
|
|
4
|
-
export class Normalizator {
|
|
5
|
-
|
|
6
|
-
public static getNormalizedInfo(model: ModelDto) {
|
|
7
|
-
let subPath = '';
|
|
8
|
-
let filename = '';
|
|
9
|
-
let modelName = '';
|
|
10
|
-
|
|
11
|
-
if (model.name && model.name.includes('.')) {
|
|
12
|
-
subPath = model.name.split('.').slice(0, -1).join('');
|
|
13
|
-
subPath = `${Utils.toDartFileName(subPath)}/models`;
|
|
14
|
-
filename = model.name.split('.').pop()!;
|
|
15
|
-
modelName = Utils.toDartClassName(filename) ?? filename;
|
|
16
|
-
filename = Utils.toDartFileName(filename!);
|
|
17
|
-
} else {
|
|
18
|
-
subPath = '';
|
|
19
|
-
filename = Utils.toDartFileName(model.name);
|
|
20
|
-
modelName = Utils.toDartClassName(model.name) ?? model.name;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
filename: filename,
|
|
25
|
-
subPath: subPath,
|
|
26
|
-
modelName: modelName,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public static getNormalizedTypeName(typeName: string): string {
|
|
31
|
-
let formattedTypeName = typeName.split('.').pop()!;
|
|
32
|
-
return Utils.toDartClassName(formattedTypeName) ?? typeName;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static mapTsTypeToDart(type: string): string {
|
|
36
|
-
const normalized = type.trim().toLowerCase();
|
|
37
|
-
|
|
38
|
-
if (normalized.endsWith("[]")) {
|
|
39
|
-
const inner = normalized.slice(0, -2).trim();
|
|
40
|
-
return `List<${Normalizator.mapTsTypeToDart(inner)}>`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
switch (normalized) {
|
|
44
|
-
case "string":
|
|
45
|
-
case "uuid":
|
|
46
|
-
case "date":
|
|
47
|
-
return "String";
|
|
48
|
-
case "dateTime":
|
|
49
|
-
return "DateTime";
|
|
50
|
-
case "number":
|
|
51
|
-
case "float":
|
|
52
|
-
case "double":
|
|
53
|
-
return "double";
|
|
54
|
-
case "integer":
|
|
55
|
-
case "int":
|
|
56
|
-
case "long":
|
|
57
|
-
return "int";
|
|
58
|
-
case "boolean":
|
|
59
|
-
case "bool":
|
|
60
|
-
return "bool";
|
|
61
|
-
case "any":
|
|
62
|
-
case "object":
|
|
63
|
-
return "dynamic";
|
|
64
|
-
case "null":
|
|
65
|
-
case "undefined":
|
|
66
|
-
return "Null";
|
|
67
|
-
default:
|
|
68
|
-
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
69
|
-
return Utils.toPascalCase(type);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
1
|
+
import { ModelDto } from "@src/models/model-dto.js";
|
|
2
|
+
import { Utils } from "../utils.js";
|
|
3
|
+
|
|
4
|
+
export class Normalizator {
|
|
5
|
+
|
|
6
|
+
public static getNormalizedInfo(model: ModelDto) {
|
|
7
|
+
let subPath = '';
|
|
8
|
+
let filename = '';
|
|
9
|
+
let modelName = '';
|
|
10
|
+
|
|
11
|
+
if (model.name && model.name.includes('.')) {
|
|
12
|
+
subPath = model.name.split('.').slice(0, -1).join('');
|
|
13
|
+
subPath = `${Utils.toDartFileName(subPath)}/models`;
|
|
14
|
+
filename = model.name.split('.').pop()!;
|
|
15
|
+
modelName = Utils.toDartClassName(filename) ?? filename;
|
|
16
|
+
filename = Utils.toDartFileName(filename!);
|
|
17
|
+
} else {
|
|
18
|
+
subPath = '';
|
|
19
|
+
filename = Utils.toDartFileName(model.name);
|
|
20
|
+
modelName = Utils.toDartClassName(model.name) ?? model.name;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
filename: filename,
|
|
25
|
+
subPath: subPath,
|
|
26
|
+
modelName: modelName,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static getNormalizedTypeName(typeName: string): string {
|
|
31
|
+
let formattedTypeName = typeName.split('.').pop()!;
|
|
32
|
+
return Utils.toDartClassName(formattedTypeName) ?? typeName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static mapTsTypeToDart(type: string): string {
|
|
36
|
+
const normalized = type.trim().toLowerCase();
|
|
37
|
+
|
|
38
|
+
if (normalized.endsWith("[]")) {
|
|
39
|
+
const inner = normalized.slice(0, -2).trim();
|
|
40
|
+
return `List<${Normalizator.mapTsTypeToDart(inner)}>`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
switch (normalized) {
|
|
44
|
+
case "string":
|
|
45
|
+
case "uuid":
|
|
46
|
+
case "date":
|
|
47
|
+
return "String";
|
|
48
|
+
case "dateTime":
|
|
49
|
+
return "DateTime";
|
|
50
|
+
case "number":
|
|
51
|
+
case "float":
|
|
52
|
+
case "double":
|
|
53
|
+
return "double";
|
|
54
|
+
case "integer":
|
|
55
|
+
case "int":
|
|
56
|
+
case "long":
|
|
57
|
+
return "int";
|
|
58
|
+
case "boolean":
|
|
59
|
+
case "bool":
|
|
60
|
+
return "bool";
|
|
61
|
+
case "any":
|
|
62
|
+
case "object":
|
|
63
|
+
return "dynamic";
|
|
64
|
+
case "null":
|
|
65
|
+
case "undefined":
|
|
66
|
+
return "Null";
|
|
67
|
+
default:
|
|
68
|
+
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
69
|
+
return Utils.toPascalCase(type);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
73
|
}
|
|
@@ -1,36 +1,49 @@
|
|
|
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}}(
|
|
14
|
-
{{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
15
|
-
{{#queryParams}}
|
|
16
|
-
{{type}}{{#nullable}}?{{/nullable}} {{name}},
|
|
17
|
-
{{/queryParams}}
|
|
18
|
-
) async {
|
|
19
|
-
final response = await _dio.{{httpMethod}}(
|
|
20
|
-
'{{{path}}}',
|
|
21
|
-
{{#haveRequest}}
|
|
22
|
-
data: request.toJson(),
|
|
23
|
-
{{/haveRequest}}
|
|
24
|
-
{{^haveRequest}}
|
|
25
|
-
queryParameters: {
|
|
26
|
-
{{#queryParams}}
|
|
27
|
-
{{#nullable}}if ({{name}} != null) {{/nullable}}'{{name}}': {{name}},
|
|
28
|
-
{{/queryParams}}
|
|
29
|
-
},
|
|
30
|
-
{{/haveRequest}}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
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}}(
|
|
14
|
+
{{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
15
|
+
{{#queryParams}}
|
|
16
|
+
{{type}}{{#nullable}}?{{/nullable}} {{name}},
|
|
17
|
+
{{/queryParams}}
|
|
18
|
+
) async {
|
|
19
|
+
final response = await _dio.{{httpMethod}}(
|
|
20
|
+
'{{{path}}}',
|
|
21
|
+
{{#haveRequest}}
|
|
22
|
+
data: request.toJson(),
|
|
23
|
+
{{/haveRequest}}
|
|
24
|
+
{{^haveRequest}}
|
|
25
|
+
queryParameters: {
|
|
26
|
+
{{#queryParams}}
|
|
27
|
+
{{#nullable}}if ({{name}} != null) {{/nullable}}'{{name}}': {{name}},
|
|
28
|
+
{{/queryParams}}
|
|
29
|
+
},
|
|
30
|
+
{{/haveRequest}}
|
|
31
|
+
);
|
|
32
|
+
{{#isResponseNativeType}}
|
|
33
|
+
return parseNative<{{responseType}}>(response.data);
|
|
34
|
+
{{/isResponseNativeType}}
|
|
35
|
+
{{^isResponseNativeType}}
|
|
36
|
+
return {{responseType}}.fromJson(response.data);
|
|
37
|
+
{{/isResponseNativeType}}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
{{/endpoints}}
|
|
41
|
+
|
|
42
|
+
T parseNative<T>(dynamic data) {
|
|
43
|
+
if (T == int) return int.parse(data.toString()) as T;
|
|
44
|
+
if (T == double) return double.parse(data.toString()) as T;
|
|
45
|
+
if (T == String) return data as T;
|
|
46
|
+
if (T == bool) return data as T;
|
|
47
|
+
throw UnsupportedError('Unsupported native type $T');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
-
{{#imports}}
|
|
3
|
-
{{{.}}}
|
|
4
|
-
{{/imports}}
|
|
5
|
-
|
|
6
|
-
@JsonEnum(fieldRename: FieldRename.pascal)
|
|
7
|
-
enum {{enumName}} {
|
|
8
|
-
{{#fields}}
|
|
9
|
-
@JsonValue({{value}})
|
|
10
|
-
{{name}}({{value}}){{#isLast}};{{/isLast}}{{^isLast}},{{/isLast}}
|
|
11
|
-
{{/fields}}
|
|
12
|
-
|
|
13
|
-
final int value;
|
|
14
|
-
const {{enumName}}(this.value);
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
{{#imports}}
|
|
3
|
+
{{{.}}}
|
|
4
|
+
{{/imports}}
|
|
5
|
+
|
|
6
|
+
@JsonEnum(fieldRename: FieldRename.pascal)
|
|
7
|
+
enum {{enumName}} {
|
|
8
|
+
{{#fields}}
|
|
9
|
+
@JsonValue({{value}})
|
|
10
|
+
{{name}}({{value}}){{#isLast}};{{/isLast}}{{^isLast}},{{/isLast}}
|
|
11
|
+
{{/fields}}
|
|
12
|
+
|
|
13
|
+
final int value;
|
|
14
|
+
const {{enumName}}(this.value);
|
|
15
15
|
}
|
|
@@ -1,18 +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 {{className}} with _${{className}} {
|
|
11
|
-
const factory {{className}}({
|
|
12
|
-
{{#fields}}
|
|
13
|
-
{{required}}{{{type}}}{{nullable}} {{name}},
|
|
14
|
-
{{/fields}}
|
|
15
|
-
}) = _{{className}};
|
|
16
|
-
|
|
17
|
-
factory {{className}}.fromJson(Map<String, dynamic> json) => _${{className}}FromJson(json);
|
|
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 {{className}} with _${{className}} {
|
|
11
|
+
const factory {{className}}({
|
|
12
|
+
{{#fields}}
|
|
13
|
+
{{required}}{{{type}}}{{nullable}} {{name}},
|
|
14
|
+
{{/fields}}
|
|
15
|
+
}) = _{{className}};
|
|
16
|
+
|
|
17
|
+
factory {{className}}.fromJson(Map<String, dynamic> json) => _${{className}}FromJson(json);
|
|
18
18
|
}
|