forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
39 lines (35 loc) · 1.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { TypeScriptGenerator } from '../../src';
const generator = new TypeScriptGenerator({
typeMapping: {
Float: ({ dependencyManager }) => {
// Let let the TypeScript dependency manager handle rendering the dependency based on the TypeScript options (i.e moduleSystem).
dependencyManager.addTypeScriptDependency(
'MyCustomClass',
'../some/path/to/MyCustomClass'
);
// Or just do it manually, but then the moduleSystem options is not uphold. This is what most generators support
// dependencyManager.addDependency('import MyCustomClass from \'../some/path/to/class\';');
// Return the type to use for this float model
return 'MyCustomClass';
}
}
});
const jsonSchemaDraft7 = {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
additionalProperties: false,
properties: {
someProperty: {
type: 'number'
}
}
};
export async function generate(): Promise<void> {
const models = await generator.generate(jsonSchemaDraft7);
for (const model of models) {
console.log(model.result);
}
}
if (require.main === module) {
generate();
}