1
1
import Parser from 'tree-sitter' ;
2
2
// @ts -ignore
3
3
import JSONLanguage from 'tree-sitter-json' ;
4
- import { JsonDocument , JsonObject , JsonProperty , JsonArray } from 'apidom-ast' ;
5
4
import $RefParser from '@apidevtools/json-schema-ref-parser' ;
6
5
import * as apiDOM from 'apidom' ;
6
+ import { Error , JsonArray , JsonDocument , JsonObject , JsonProperty } from 'apidom-ast' ;
7
7
import openapi3_1 from 'apidom-ns-openapi3-1' ;
8
8
import { transform } from './cst' ;
9
9
import specification from './specification' ;
10
10
import { visit } from './visitors' ;
11
11
12
12
const parse = async (
13
13
source : string ,
14
- {
15
- sourceMap = false ,
16
- specObj = specification ,
17
- keyMap = {
18
- // @ts -ignore
19
- [ JsonDocument . type ] : [ 'child' ] ,
20
- // @ts -ignore
21
- [ JsonObject . type ] : [ 'properties' ] ,
22
- // @ts -ignore
23
- [ JsonProperty . type ] : [ 'key' , 'value' ] ,
24
- // @ts -ignore
25
- [ JsonArray . type ] : [ 'items' ] ,
26
- } ,
27
- } = { } ,
14
+ { sourceMap = false , specObj = specification } = { } ,
28
15
) : Promise < apiDOM . ParseResultElement > => {
29
16
const resolvedSpecObj = await $RefParser . dereference ( specObj ) ;
30
17
const namespace = apiDOM . createNamespace ( openapi3_1 ) ;
@@ -39,6 +26,19 @@ const parse = async (
39
26
const cst = parser . parse ( source ) ;
40
27
const ast = transform ( cst ) ;
41
28
29
+ const keyMap = {
30
+ // @ts -ignore
31
+ [ JsonDocument . type ] : [ 'children' ] ,
32
+ // @ts -ignore
33
+ [ JsonObject . type ] : [ 'children' ] ,
34
+ // @ts -ignore
35
+ [ JsonProperty . type ] : [ 'children' ] ,
36
+ // @ts -ignore
37
+ [ JsonArray . type ] : [ 'children' ] ,
38
+ // @ts -ignore
39
+ [ Error . type ] : [ 'children' ] ,
40
+ } ;
41
+
42
42
visit ( ast . rootNode , documentVisitor , {
43
43
keyMap,
44
44
// @ts -ignore
0 commit comments