@@ -5,25 +5,35 @@ import { pascalCase } from 'pascal-case';
55
66declare type MyAjv = import ( 'ajv' ) . default ;
77
8+ export function defaultTitleFunction ( schema : JSONSchema4 ) : string {
9+ return `${ schema . title } Props` ;
10+ }
11+
12+ export function defaultFilenameFunction ( schema : JSONSchema4 ) : string {
13+ return `${ pascalCase ( getSchemaName ( schema . $id ) ) } Props` ;
14+ }
15+
816export async function createTypes (
917 schemaIds : string [ ] ,
1018 renderImportName : ( schemaId : string ) => string ,
1119 renderImportStatement : ( schemaId : string ) => string ,
1220 ajv : MyAjv ,
13- options ?: Partial < Options >
21+ options ?: Partial < Options > ,
22+ titleFunction : ( schema : JSONSchema4 ) => string = defaultTitleFunction ,
23+ filenameFunction : ( schema : JSONSchema4 ) => string = defaultFilenameFunction
1424) : Promise < Record < string , string > > {
1525 const generatedTypings : Record < string , string > = { } ;
1626 const schemas = getSchemasForIds ( schemaIds , ajv ) ;
1727
18- for ( const schema of schemas ) {
28+ for ( const schema of schemas as JSONSchema4 [ ] ) {
1929 if ( ! schema . $id ) throw new Error ( "Can't process a schema without $id" ) ;
2030
2131 const typings = await compile (
2232 {
23- ...( schema as JSONSchema4 ) ,
24- title : ` ${ schema . title } Props`
33+ ...schema ,
34+ title : titleFunction ( schema )
2535 } ,
26- ` ${ pascalCase ( getSchemaName ( schema . $id ) ) } Props` ,
36+ filenameFunction ( schema ) ,
2737 {
2838 declareExternallyReferenced : true ,
2939 $refOptions : {
0 commit comments