@@ -16,17 +16,20 @@ export async function convertSchemaToOptions(schema: string): Promise<Option[]>
16
16
}
17
17
18
18
function 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 ) => {
21
21
const fullSchema = parseJson ( schemaText ) ;
22
+ if ( ! isJsonObject ( fullSchema ) ) {
23
+ return Promise . resolve ( [ ] ) ;
24
+ }
22
25
const traverseOptions = { } ;
23
26
const options : Option [ ] = [ ] ;
24
27
function postCallback ( schema : JsonObject ,
25
28
jsonPointer : string ,
26
- rootSchema : string ,
27
- parentJsonPointer : string ,
29
+ _rootSchema : string ,
30
+ _parentJsonPointer : string ,
28
31
parentKeyword : string ,
29
- parentSchema : string ,
32
+ _parentSchema : string ,
30
33
property : string ) {
31
34
if ( parentKeyword === 'properties' ) {
32
35
let includeOption = true ;
@@ -43,15 +46,15 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
43
46
}
44
47
let $default : OptionSmartDefault | undefined = undefined ;
45
48
if ( schema . $default !== null && isJsonObject ( schema . $default ) ) {
46
- $default = < OptionSmartDefault > schema . $default ;
49
+ $default = schema . $default as OptionSmartDefault ;
47
50
}
48
51
let required = false ;
49
52
if ( typeof schema . required === 'boolean' ) {
50
53
required = schema . required ;
51
54
}
52
55
let aliases : string [ ] | undefined = undefined ;
53
56
if ( typeof schema . aliases === 'object' && Array . isArray ( schema . aliases ) ) {
54
- aliases = < string [ ] > schema . aliases ;
57
+ aliases = schema . aliases as string [ ] ;
55
58
}
56
59
let format : string | undefined = undefined ;
57
60
if ( typeof schema . format === 'string' ) {
@@ -86,7 +89,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
86
89
87
90
const callbacks = { post : postCallback } ;
88
91
89
- jsonSchemaTraverse ( < object > fullSchema , traverseOptions , callbacks ) ;
92
+ jsonSchemaTraverse ( fullSchema , traverseOptions , callbacks ) ;
90
93
} ) ;
91
94
}
92
95
0 commit comments