@0kmpo/openapi-clean-arch-generator 1.3.14 → 1.4.0
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 +132 -63
- package/dist/main.js +31 -3
- package/dist/package.json +1 -1
- package/dist/src/generators/clean-arch.generator.js +221 -145
- package/dist/src/generators/dto.generator.js +48 -24
- package/dist/src/generators/report.generator.js +6 -0
- package/dist/src/utils/config.js +3 -0
- package/dist/src/utils/example-validator.js +86 -0
- package/dist/src/utils/mock-value-resolver.js +19 -7
- package/dist/src/utils/name-formatter.js +133 -2
- package/dist/templates/api.repository.contract.mustache +1 -1
- package/dist/templates/api.repository.impl.mock.mustache +2 -2
- package/dist/templates/api.repository.impl.mustache +5 -5
- package/dist/templates/api.repository.impl.spec.mustache +2 -2
- package/dist/templates/api.use-cases.contract.mustache +1 -1
- package/dist/templates/api.use-cases.impl.mustache +2 -2
- package/dist/templates/api.use-cases.impl.spec.mustache +2 -2
- package/dist/templates/api.use-cases.mock.mustache +2 -2
- package/dist/templates/dto.mock.mustache +1 -1
- package/dist/templates/mapper.mustache +2 -2
- package/dist/templates/mapper.spec.mustache +2 -2
- package/dist/templates/model-entity.mustache +1 -1
- package/dist/templates/model-entity.spec.mustache +4 -0
- package/dist/templates/model.mock.mustache +2 -2
- package/dist/templates/repository.provider.mock.mustache +2 -2
- package/dist/templates/repository.provider.mustache +2 -2
- package/dist/templates/use-cases.provider.mock.mustache +2 -2
- package/dist/templates/use-cases.provider.mustache +2 -2
- package/package.json +1 -1
package/dist/src/utils/config.js
CHANGED
|
@@ -66,6 +66,9 @@ function generateDefaultConfig(analysis, tagSummaries, cliOptions, apiKeys) {
|
|
|
66
66
|
if (cliOptions.templates) {
|
|
67
67
|
config.templates = cliOptions.templates;
|
|
68
68
|
}
|
|
69
|
+
if (cliOptions.baseName) {
|
|
70
|
+
config.baseName = cliOptions.baseName;
|
|
71
|
+
}
|
|
69
72
|
return config;
|
|
70
73
|
}
|
|
71
74
|
/**
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that OpenAPI `example` values match their declared `type`.
|
|
4
|
+
*
|
|
5
|
+
* YAML parses unquoted values by native type (e.g. `example: 68131` becomes a JS number
|
|
6
|
+
* even when the schema declares `type: string`). This module detects such mismatches,
|
|
7
|
+
* coerces them when possible, and accumulates warnings for the generation report.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.validateExample = validateExample;
|
|
11
|
+
exports.registerMismatch = registerMismatch;
|
|
12
|
+
exports.getExampleMismatches = getExampleMismatches;
|
|
13
|
+
exports.clearExampleMismatches = clearExampleMismatches;
|
|
14
|
+
// Module-level accumulator — reset between runs via `clearExampleMismatches()`.
|
|
15
|
+
let mismatches = [];
|
|
16
|
+
/**
|
|
17
|
+
* Validates an `example` value against a declared OpenAPI `type`.
|
|
18
|
+
*
|
|
19
|
+
* @returns `{ valid: true }` when types already match, or
|
|
20
|
+
* `{ valid: false, coerced: <value> }` when the value was coerced, or
|
|
21
|
+
* `{ valid: false }` when coercion is not possible (caller should ignore the example).
|
|
22
|
+
*/
|
|
23
|
+
function validateExample(declaredType, example) {
|
|
24
|
+
if (declaredType === undefined)
|
|
25
|
+
return { valid: true };
|
|
26
|
+
const jsType = typeof example;
|
|
27
|
+
// ── string declared ──────────────────────────────────────────────────────
|
|
28
|
+
if (declaredType === 'string') {
|
|
29
|
+
if (jsType === 'string')
|
|
30
|
+
return { valid: true };
|
|
31
|
+
// number or boolean → coerce to string
|
|
32
|
+
if (jsType === 'number' || jsType === 'boolean') {
|
|
33
|
+
return { valid: false, coerced: String(example) };
|
|
34
|
+
}
|
|
35
|
+
return { valid: false };
|
|
36
|
+
}
|
|
37
|
+
// ── integer / number declared ────────────────────────────────────────────
|
|
38
|
+
if (declaredType === 'integer' || declaredType === 'number') {
|
|
39
|
+
if (jsType === 'number')
|
|
40
|
+
return { valid: true };
|
|
41
|
+
if (jsType === 'string') {
|
|
42
|
+
const parsed = Number(example);
|
|
43
|
+
if (!Number.isNaN(parsed))
|
|
44
|
+
return { valid: false, coerced: parsed };
|
|
45
|
+
return { valid: false }; // unparseable → ignore
|
|
46
|
+
}
|
|
47
|
+
return { valid: false };
|
|
48
|
+
}
|
|
49
|
+
// ── boolean declared ─────────────────────────────────────────────────────
|
|
50
|
+
if (declaredType === 'boolean') {
|
|
51
|
+
if (jsType === 'boolean')
|
|
52
|
+
return { valid: true };
|
|
53
|
+
if (jsType === 'string') {
|
|
54
|
+
const lower = example.toLowerCase();
|
|
55
|
+
if (lower === 'true')
|
|
56
|
+
return { valid: false, coerced: true };
|
|
57
|
+
if (lower === 'false')
|
|
58
|
+
return { valid: false, coerced: false };
|
|
59
|
+
}
|
|
60
|
+
return { valid: false }; // cannot coerce
|
|
61
|
+
}
|
|
62
|
+
// Other types (object, array, etc.) — no validation
|
|
63
|
+
return { valid: true };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Records a mismatch so it can be retrieved later for console warnings and the report.
|
|
67
|
+
*/
|
|
68
|
+
function registerMismatch(schemaName, propertyName, declaredType, exampleValue, action, coercedValue) {
|
|
69
|
+
mismatches.push({
|
|
70
|
+
schemaName,
|
|
71
|
+
propertyName,
|
|
72
|
+
declaredType,
|
|
73
|
+
exampleValue,
|
|
74
|
+
exampleJsType: typeof exampleValue,
|
|
75
|
+
action,
|
|
76
|
+
coercedValue
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Returns all recorded mismatches. */
|
|
80
|
+
function getExampleMismatches() {
|
|
81
|
+
return mismatches;
|
|
82
|
+
}
|
|
83
|
+
/** Clears all recorded mismatches (call before each generation run). */
|
|
84
|
+
function clearExampleMismatches() {
|
|
85
|
+
mismatches = [];
|
|
86
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveMockValue = resolveMockValue;
|
|
4
|
+
const example_validator_1 = require("./example-validator");
|
|
4
5
|
/**
|
|
5
6
|
* Resolves a TypeScript literal string to use as a mock value for a single schema property.
|
|
6
7
|
*
|
|
7
8
|
* Priority chain:
|
|
8
9
|
* $ref mock call → array $ref mock call → enum[0] → example → format fallback → type default
|
|
9
10
|
*
|
|
10
|
-
* @param propName
|
|
11
|
-
* @param prop
|
|
12
|
-
* @param context
|
|
11
|
+
* @param propName Property name (used for format heuristics such as "email").
|
|
12
|
+
* @param prop Raw OpenAPI property definition.
|
|
13
|
+
* @param context 'dto' generates `mockFooDto()`, 'model' generates `mockFooModel()`.
|
|
14
|
+
* @param schemaName Parent schema name (used for mismatch reporting).
|
|
13
15
|
*/
|
|
14
|
-
function resolveMockValue(propName, prop, context = 'dto') {
|
|
16
|
+
function resolveMockValue(propName, prop, context = 'dto', schemaName = 'unknown') {
|
|
15
17
|
const suffix = context === 'dto' ? 'Dto' : 'Model';
|
|
16
18
|
// 1. Direct $ref → call the referenced mock factory
|
|
17
19
|
if (prop.$ref) {
|
|
@@ -31,9 +33,19 @@ function resolveMockValue(propName, prop, context = 'dto') {
|
|
|
31
33
|
const first = prop.enum[0];
|
|
32
34
|
return typeof first === 'string' ? `'${first}'` : String(first);
|
|
33
35
|
}
|
|
34
|
-
// 5. Example value
|
|
35
|
-
if (prop.example !== undefined)
|
|
36
|
-
|
|
36
|
+
// 5. Example value — validated and coerced if needed
|
|
37
|
+
if (prop.example !== undefined) {
|
|
38
|
+
const result = (0, example_validator_1.validateExample)(prop.type, prop.example);
|
|
39
|
+
if (result.valid) {
|
|
40
|
+
return formatLiteral(prop.example);
|
|
41
|
+
}
|
|
42
|
+
if (result.coerced !== undefined) {
|
|
43
|
+
(0, example_validator_1.registerMismatch)(schemaName, propName, prop.type, prop.example, 'coerced', result.coerced);
|
|
44
|
+
return formatLiteral(result.coerced);
|
|
45
|
+
}
|
|
46
|
+
// Cannot coerce — register and fall through to defaults
|
|
47
|
+
(0, example_validator_1.registerMismatch)(schemaName, propName, prop.type, prop.example, 'ignored');
|
|
48
|
+
}
|
|
37
49
|
// 6. Format-aware fallbacks (when no example is provided)
|
|
38
50
|
if (prop.format === 'date-time')
|
|
39
51
|
return `'2024-01-01T00:00:00.000Z'`;
|
|
@@ -1,16 +1,147 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toPascalCase = toPascalCase;
|
|
3
7
|
exports.toCamelCase = toCamelCase;
|
|
8
|
+
exports.isReservedWord = isReservedWord;
|
|
9
|
+
exports.safePropertyName = safePropertyName;
|
|
10
|
+
exports.deriveBaseName = deriveBaseName;
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const logger_1 = require("./logger");
|
|
4
13
|
/**
|
|
5
|
-
* Converts a
|
|
14
|
+
* Converts a string to PascalCase, handling spaces, hyphens and underscores.
|
|
15
|
+
* Used to derive class names from schema/tag names.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* toPascalCase('Product Format') // 'ProductFormat'
|
|
19
|
+
* toPascalCase('user-response') // 'UserResponse'
|
|
20
|
+
* toPascalCase('UserSchema') // 'UserSchema'
|
|
21
|
+
*/
|
|
22
|
+
function toPascalCase(name) {
|
|
23
|
+
if (!name)
|
|
24
|
+
return name;
|
|
25
|
+
return name
|
|
26
|
+
.split(/[\s\-_]+/)
|
|
27
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
28
|
+
.join('');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a string to camelCase, handling spaces, hyphens and underscores.
|
|
6
32
|
* Used to derive class filenames and variable names from schema/tag names.
|
|
7
33
|
*
|
|
8
34
|
* @example
|
|
35
|
+
* toCamelCase('Product Format') // 'productFormat'
|
|
9
36
|
* toCamelCase('ProductResponse') // 'productResponse'
|
|
10
37
|
* toCamelCase('UserSchema') // 'userSchema'
|
|
11
38
|
*/
|
|
12
39
|
function toCamelCase(name) {
|
|
13
40
|
if (!name)
|
|
14
41
|
return name;
|
|
15
|
-
|
|
42
|
+
const pascal = toPascalCase(name);
|
|
43
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
44
|
+
}
|
|
45
|
+
const JS_RESERVED_WORDS = new Set([
|
|
46
|
+
'abstract',
|
|
47
|
+
'arguments',
|
|
48
|
+
'await',
|
|
49
|
+
'boolean',
|
|
50
|
+
'break',
|
|
51
|
+
'byte',
|
|
52
|
+
'case',
|
|
53
|
+
'catch',
|
|
54
|
+
'char',
|
|
55
|
+
'class',
|
|
56
|
+
'const',
|
|
57
|
+
'continue',
|
|
58
|
+
'debugger',
|
|
59
|
+
'default',
|
|
60
|
+
'delete',
|
|
61
|
+
'do',
|
|
62
|
+
'double',
|
|
63
|
+
'else',
|
|
64
|
+
'enum',
|
|
65
|
+
'eval',
|
|
66
|
+
'export',
|
|
67
|
+
'extends',
|
|
68
|
+
'false',
|
|
69
|
+
'final',
|
|
70
|
+
'finally',
|
|
71
|
+
'float',
|
|
72
|
+
'for',
|
|
73
|
+
'function',
|
|
74
|
+
'goto',
|
|
75
|
+
'if',
|
|
76
|
+
'implements',
|
|
77
|
+
'import',
|
|
78
|
+
'in',
|
|
79
|
+
'instanceof',
|
|
80
|
+
'int',
|
|
81
|
+
'interface',
|
|
82
|
+
'let',
|
|
83
|
+
'long',
|
|
84
|
+
'native',
|
|
85
|
+
'new',
|
|
86
|
+
'null',
|
|
87
|
+
'package',
|
|
88
|
+
'private',
|
|
89
|
+
'protected',
|
|
90
|
+
'public',
|
|
91
|
+
'return',
|
|
92
|
+
'short',
|
|
93
|
+
'static',
|
|
94
|
+
'super',
|
|
95
|
+
'switch',
|
|
96
|
+
'synchronized',
|
|
97
|
+
'this',
|
|
98
|
+
'throw',
|
|
99
|
+
'throws',
|
|
100
|
+
'transient',
|
|
101
|
+
'true',
|
|
102
|
+
'try',
|
|
103
|
+
'typeof',
|
|
104
|
+
'undefined',
|
|
105
|
+
'var',
|
|
106
|
+
'void',
|
|
107
|
+
'volatile',
|
|
108
|
+
'while',
|
|
109
|
+
'with',
|
|
110
|
+
'yield'
|
|
111
|
+
]);
|
|
112
|
+
/** Returns true if the given name is a JS/TS reserved word. */
|
|
113
|
+
function isReservedWord(name) {
|
|
114
|
+
return JS_RESERVED_WORDS.has(name);
|
|
115
|
+
}
|
|
116
|
+
/** Prefixes reserved words with `_` to produce a safe identifier. */
|
|
117
|
+
function safePropertyName(name) {
|
|
118
|
+
return isReservedWord(name) ? `_${name}` : name;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Derives a baseName from a swagger file path, used as the top-level folder
|
|
122
|
+
* that groups all generated artefacts for that contract.
|
|
123
|
+
*
|
|
124
|
+
* Primary rule: takes the token immediately before `-swagger` (case-insensitive).
|
|
125
|
+
* Fallback: takes the last token of the basename and emits a warning.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* deriveBaseName('my-app-swagger.yaml') // 'app'
|
|
129
|
+
* deriveBaseName('aprovalm-swagger.yaml') // 'aprovalm'
|
|
130
|
+
* deriveBaseName('backoffice.yaml') // 'backoffice' + warning
|
|
131
|
+
* deriveBaseName('my-backoffice.yaml') // 'backoffice' + warning
|
|
132
|
+
*/
|
|
133
|
+
function deriveBaseName(filepath) {
|
|
134
|
+
const base = path_1.default.basename(filepath, path_1.default.extname(filepath));
|
|
135
|
+
const tokens = base.split(/[-_]+/);
|
|
136
|
+
const swaggerIdx = tokens.findIndex((t) => t.toLowerCase() === 'swagger');
|
|
137
|
+
let raw;
|
|
138
|
+
if (swaggerIdx > 0) {
|
|
139
|
+
raw = tokens[swaggerIdx - 1];
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
raw = tokens[tokens.length - 1];
|
|
143
|
+
(0, logger_1.logWarning)(`Could not find "-swagger" segment in "${base}". ` +
|
|
144
|
+
`Using "${raw}" as baseName. Use -k to override.`);
|
|
145
|
+
}
|
|
146
|
+
return toCamelCase(raw);
|
|
16
147
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { InjectionToken } from '@angular/core';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
{{#imports}}
|
|
7
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
7
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
8
8
|
{{/imports}}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { MockService } from 'ng-mocks';
|
|
5
5
|
import { of } from 'rxjs';
|
|
6
6
|
|
|
7
|
-
import { {{classname}}RepositoryImpl } from '@/data/repositories/{{classFilename}}.repository.impl';
|
|
7
|
+
import { {{classname}}RepositoryImpl } from '@/data/repositories/{{tagFolderPath}}/{{classFilename}}.repository.impl';
|
|
8
8
|
{{#returnImports}}
|
|
9
|
-
import { mock{{classname}}Model } from '@/entities/models/{{classFilename}}.model.mock';
|
|
9
|
+
import { mock{{classname}}Model } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model.mock';
|
|
10
10
|
{{/returnImports}}
|
|
11
11
|
|
|
12
12
|
export const mock{{classname}}RepositoryImpl = () =>
|
|
@@ -9,14 +9,14 @@ import { environment } from '@environment';
|
|
|
9
9
|
|
|
10
10
|
import { MRepository } from '@mercadona/core/utils/repository';
|
|
11
11
|
|
|
12
|
-
import { {{classname}}Repository } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
|
12
|
+
import { {{classname}}Repository } from '@/domain/repositories/{{tagFolderPath}}/{{classFilename}}.repository.contract';
|
|
13
13
|
{{#returnImports}}
|
|
14
|
-
import { {{classname}}Dto } from '@/dtos/{{classFilename}}.dto';
|
|
15
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
16
|
-
import { {{classVarName}}Mapper } from '@/mappers/{{classFilename}}.mapper';
|
|
14
|
+
import { {{classname}}Dto } from '@/dtos/{{tagFolderPath}}/{{classFilename}}.dto';
|
|
15
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
16
|
+
import { {{classVarName}}Mapper } from '@/mappers/{{tagFolderPath}}/{{classFilename}}.mapper';
|
|
17
17
|
{{/returnImports}}
|
|
18
18
|
{{#paramImports}}
|
|
19
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
19
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
20
20
|
{{/paramImports}}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -6,8 +6,8 @@ import { TestBed } from '@angular/core/testing';
|
|
|
6
6
|
|
|
7
7
|
import { {{classname}}RepositoryImpl } from './{{classFilename}}.repository.impl';
|
|
8
8
|
{{#returnImports}}
|
|
9
|
-
import { mock{{classname}}Dto } from '@/dtos/{{classFilename}}.dto.mock';
|
|
10
|
-
import { mock{{classname}}Model } from '@/entities/models/{{classFilename}}.model.mock';
|
|
9
|
+
import { mock{{classname}}Dto } from '@/dtos/{{tagFolderPath}}/{{classFilename}}.dto.mock';
|
|
10
|
+
import { mock{{classname}}Model } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model.mock';
|
|
11
11
|
{{/returnImports}}
|
|
12
12
|
|
|
13
13
|
describe('{{classname}}RepositoryImpl', () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { InjectionToken } from '@angular/core';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
{{#imports}}
|
|
7
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
7
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
8
8
|
{{/imports}}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -6,9 +6,9 @@ import { Observable } from 'rxjs';
|
|
|
6
6
|
|
|
7
7
|
import { {{classname}}UseCases } from './{{classFilename}}.use-cases.contract';
|
|
8
8
|
|
|
9
|
-
import { {{constantName}}_REPOSITORY, {{classname}}Repository } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
|
9
|
+
import { {{constantName}}_REPOSITORY, {{classname}}Repository } from '@/domain/repositories/{{tagFolderPath}}/{{classFilename}}.repository.contract';
|
|
10
10
|
{{#imports}}
|
|
11
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
11
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
12
12
|
{{/imports}}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -6,9 +6,9 @@ import { of } from 'rxjs';
|
|
|
6
6
|
|
|
7
7
|
import { {{classname}}UseCasesImpl } from './{{classFilename}}.use-cases.impl';
|
|
8
8
|
|
|
9
|
-
import { {{constantName}}_REPOSITORY, {{classname}}Repository } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
|
9
|
+
import { {{constantName}}_REPOSITORY, {{classname}}Repository } from '@/domain/repositories/{{tagFolderPath}}/{{classFilename}}.repository.contract';
|
|
10
10
|
{{#returnImports}}
|
|
11
|
-
import { mock{{classname}}Model } from '@/entities/models/{{classFilename}}.model.mock';
|
|
11
|
+
import { mock{{classname}}Model } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model.mock';
|
|
12
12
|
{{/returnImports}}
|
|
13
13
|
|
|
14
14
|
describe('{{classname}}UseCasesImpl', () => {
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { MockService } from 'ng-mocks';
|
|
5
5
|
import { of } from 'rxjs';
|
|
6
6
|
|
|
7
|
-
import { {{classname}}UseCasesImpl } from '@/domain/use-cases/{{classFilename}}.use-cases.impl';
|
|
7
|
+
import { {{classname}}UseCasesImpl } from '@/domain/use-cases/{{tagFolderPath}}/{{classFilename}}.use-cases.impl';
|
|
8
8
|
{{#returnImports}}
|
|
9
|
-
import { mock{{classname}}Model } from '@/entities/models/{{classFilename}}.model.mock';
|
|
9
|
+
import { mock{{classname}}Model } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model.mock';
|
|
10
10
|
{{/returnImports}}
|
|
11
11
|
|
|
12
12
|
export const mock{{classname}}UseCasesImpl = () =>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { MapFromFn } from '@mercadona/common/public';
|
|
5
5
|
import { Builder } from '@mercadona/common/utils';
|
|
6
6
|
|
|
7
|
-
import { {{classname}}Dto } from '@/dtos/{{classFilename}}.dto';
|
|
8
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
7
|
+
import { {{classname}}Dto } from '@/dtos/{{tagFolderPath}}/{{classFilename}}.dto';
|
|
8
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* {{classname}} Mapper
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
{{#model}}
|
|
3
3
|
import { {{classVarName}}Mapper } from './{{classFilename}}.mapper';
|
|
4
4
|
|
|
5
|
-
import { mock{{classname}}Dto } from '@/dtos/{{classFilename}}.dto.mock';
|
|
6
|
-
import { {{classname}} } from '@/entities/models/{{classFilename}}.model';
|
|
5
|
+
import { mock{{classname}}Dto } from '@/dtos/{{tagFolderPath}}/{{classFilename}}.dto.mock';
|
|
6
|
+
import { {{classname}} } from '@/entities/models/{{tagFolderPath}}/{{classFilename}}.model';
|
|
7
7
|
|
|
8
8
|
describe('{{classVarName}}Mapper', () => {
|
|
9
9
|
{{#vars}}
|
|
@@ -11,6 +11,7 @@ describe('{{classname}}', () => {
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
{{#vars}}
|
|
14
|
+
{{#hasMockValue}}
|
|
14
15
|
it('should allow setting {{name}}', () => {
|
|
15
16
|
const model = new {{classname}}();
|
|
16
17
|
const expected = mock{{classname}}Model();
|
|
@@ -19,13 +20,16 @@ describe('{{classname}}', () => {
|
|
|
19
20
|
expect(model.{{name}}).toBe(expected.{{name}});
|
|
20
21
|
});
|
|
21
22
|
|
|
23
|
+
{{/hasMockValue}}
|
|
22
24
|
{{/vars}}
|
|
23
25
|
it('should build a valid model from mock', () => {
|
|
24
26
|
const model = mock{{classname}}Model();
|
|
25
27
|
|
|
26
28
|
expect(model).toBeInstanceOf({{classname}});
|
|
27
29
|
{{#vars}}
|
|
30
|
+
{{#hasMockValue}}
|
|
28
31
|
expect(model.{{name}}).toBeDefined();
|
|
32
|
+
{{/hasMockValue}}
|
|
29
33
|
{{/vars}}
|
|
30
34
|
});
|
|
31
35
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{{#models}}
|
|
2
2
|
{{#model}}
|
|
3
3
|
import { {{classname}} } from './{{classFilename}}.model';
|
|
4
|
-
import { {{classVarName}}Mapper } from '@/mappers/{{classFilename}}.mapper';
|
|
5
|
-
import { mock{{classname}}Dto } from '@/dtos/{{classFilename}}.dto.mock';
|
|
4
|
+
import { {{classVarName}}Mapper } from '@/mappers/{{tagFolderPath}}/{{classFilename}}.mapper';
|
|
5
|
+
import { mock{{classname}}Dto } from '@/dtos/{{tagFolderPath}}/{{classFilename}}.dto.mock';
|
|
6
6
|
|
|
7
7
|
export const mock{{classname}}Model = (overrides: Partial<{{classname}}> = {}): {{classname}} =>
|
|
8
8
|
Object.assign(new {{classname}}(), {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
{{#operations}}
|
|
4
4
|
import { Provider } from '@angular/core';
|
|
5
5
|
|
|
6
|
-
import { {{constantName}}_REPOSITORY } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
|
7
|
-
import { mock{{classname}}RepositoryImpl } from '@/data/repositories/{{classFilename}}.repository.impl.mock';
|
|
6
|
+
import { {{constantName}}_REPOSITORY } from '@/domain/repositories/{{tagFolderPath}}/{{classFilename}}.repository.contract';
|
|
7
|
+
import { mock{{classname}}RepositoryImpl } from '@/data/repositories/{{tagFolderPath}}/{{classFilename}}.repository.impl.mock';
|
|
8
8
|
|
|
9
9
|
export function mock{{classname}}Repository(): Provider[] {
|
|
10
10
|
return [
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
{{#operations}}
|
|
4
4
|
import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';
|
|
5
5
|
|
|
6
|
-
import { {{constantName}}_REPOSITORY } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
|
7
|
-
import { {{classname}}RepositoryImpl } from '@/data/repositories/{{classFilename}}.repository.impl';
|
|
6
|
+
import { {{constantName}}_REPOSITORY } from '@/domain/repositories/{{tagFolderPath}}/{{classFilename}}.repository.contract';
|
|
7
|
+
import { {{classname}}RepositoryImpl } from '@/data/repositories/{{tagFolderPath}}/{{classFilename}}.repository.impl';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* {{classname}} Repository Provider
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
{{#operations}}
|
|
4
4
|
import { Provider } from '@angular/core';
|
|
5
5
|
|
|
6
|
-
import { {{constantName}}_USE_CASES } from '@/domain/use-cases/{{classFilename}}.use-cases.contract';
|
|
7
|
-
import { mock{{classname}}UseCasesImpl } from '@/domain/use-cases/{{classFilename}}.use-cases.mock';
|
|
6
|
+
import { {{constantName}}_USE_CASES } from '@/domain/use-cases/{{tagFolderPath}}/{{classFilename}}.use-cases.contract';
|
|
7
|
+
import { mock{{classname}}UseCasesImpl } from '@/domain/use-cases/{{tagFolderPath}}/{{classFilename}}.use-cases.mock';
|
|
8
8
|
|
|
9
9
|
export function mock{{classname}}UseCases(): Provider[] {
|
|
10
10
|
return [
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
{{#operations}}
|
|
4
4
|
import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';
|
|
5
5
|
|
|
6
|
-
import { {{constantName}}_USE_CASES } from '@/domain/use-cases/{{classFilename}}.use-cases.contract';
|
|
7
|
-
import { {{classname}}UseCasesImpl } from '@/domain/use-cases/{{classFilename}}.use-cases.impl';
|
|
6
|
+
import { {{constantName}}_USE_CASES } from '@/domain/use-cases/{{tagFolderPath}}/{{classFilename}}.use-cases.contract';
|
|
7
|
+
import { {{classname}}UseCasesImpl } from '@/domain/use-cases/{{tagFolderPath}}/{{classFilename}}.use-cases.impl';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* {{classname}} Use Cases Provider
|