@@ -16,17 +16,20 @@ export async function convertSchemaToOptions(schema: string): Promise<Option[]>
1616}
1717
1818function getOptions ( schemaText : string , onlyRootProperties = true ) : Promise < Option [ ] > {
19- // TODO: refactor promise to an observable then use `.toPromise()`
20- return new Promise ( ( resolve , reject ) => {
19+ // TODO: Use devkit core's visitJsonSchema
20+ return new Promise ( ( resolve ) => {
2121 const fullSchema = parseJson ( schemaText ) ;
22+ if ( ! isJsonObject ( fullSchema ) ) {
23+ return Promise . resolve ( [ ] ) ;
24+ }
2225 const traverseOptions = { } ;
2326 const options : Option [ ] = [ ] ;
2427 function postCallback ( schema : JsonObject ,
2528 jsonPointer : string ,
26- rootSchema : string ,
27- parentJsonPointer : string ,
29+ _rootSchema : string ,
30+ _parentJsonPointer : string ,
2831 parentKeyword : string ,
29- parentSchema : string ,
32+ _parentSchema : string ,
3033 property : string ) {
3134 if ( parentKeyword === 'properties' ) {
3235 let includeOption = true ;
@@ -43,15 +46,15 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
4346 }
4447 let $default : OptionSmartDefault | undefined = undefined ;
4548 if ( schema . $default !== null && isJsonObject ( schema . $default ) ) {
46- $default = < OptionSmartDefault > schema . $default ;
49+ $default = schema . $default as OptionSmartDefault ;
4750 }
4851 let required = false ;
4952 if ( typeof schema . required === 'boolean' ) {
5053 required = schema . required ;
5154 }
5255 let aliases : string [ ] | undefined = undefined ;
5356 if ( typeof schema . aliases === 'object' && Array . isArray ( schema . aliases ) ) {
54- aliases = < string [ ] > schema . aliases ;
57+ aliases = schema . aliases as string [ ] ;
5558 }
5659 let format : string | undefined = undefined ;
5760 if ( typeof schema . format === 'string' ) {
@@ -86,7 +89,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
8689
8790 const callbacks = { post : postCallback } ;
8891
89- jsonSchemaTraverse ( < object > fullSchema , traverseOptions , callbacks ) ;
92+ jsonSchemaTraverse ( fullSchema , traverseOptions , callbacks ) ;
9093 } ) ;
9194}
9295
0 commit comments