1
- // @ts -ignore
2
- import * as openapi3_1Adapter from '@swagger-api/apidom-parser-adapter-openapi-json-3-1' ;
3
- // @ts -ignore
4
- import * as asyncapi2Adapter from '@swagger-api/apidom-parser-adapter-asyncapi-json-2' ;
5
- // @ts -ignore
6
- import * as openapi3_1Adapter_Yaml from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1' ;
7
- // @ts -ignore
8
- import * as asyncapi2Adapter_Yaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2' ;
9
- // @ts -ignore
10
- import * as adsAdapter from '@swagger-api/apidom-parser-adapter-api-design-systems-json' ;
11
- // @ts -ignore
12
- import * as adsAdapter_Yaml from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml' ;
13
- // @ts -ignore
14
- import * as jsonParserAdapter from '@swagger-api/apidom-parser-adapter-json' ;
15
- // @ts -ignore
16
- import * as yamlParserAdapter from '@swagger-api/apidom-parser-adapter-yaml-1-2' ;
17
- // @ts -ignore
18
- import { refractorPluginReplaceEmptyElement } from '@swagger-api/apidom-ns-asyncapi-2' ;
19
- import { refractorPluginReplaceEmptyElement as refractorPluginReplaceEmptyElementOas } from '@swagger-api/apidom-ns-openapi-3-1' ;
1
+ import * as openapi3_0AdapterJson from '@swagger-api/apidom-parser-adapter-openapi-json-3-0' ;
2
+ import * as openapi3_0AdapterYaml from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-0' ;
3
+ import * as openapi3_1AdapterJson from '@swagger-api/apidom-parser-adapter-openapi-json-3-1' ;
4
+ import * as openapi3_1AdapterYaml from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1' ;
5
+ import * as asyncapi2AdapterJson from '@swagger-api/apidom-parser-adapter-asyncapi-json-2' ;
6
+ import * as asyncapi2AdapterYaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2' ;
7
+ import * as adsAdapterJson from '@swagger-api/apidom-parser-adapter-api-design-systems-json' ;
8
+ import * as adsAdapterYaml from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml' ;
9
+ import * as adapterJson from '@swagger-api/apidom-parser-adapter-json' ;
10
+ import * as adapterYaml from '@swagger-api/apidom-parser-adapter-yaml-1-2' ;
11
+ import { refractorPluginReplaceEmptyElement as refractorPluginReplaceEmptyElementAsyncAPI2 } from '@swagger-api/apidom-ns-asyncapi-2' ;
12
+ import { refractorPluginReplaceEmptyElement as refractorPluginReplaceEmptyElementOpenAPI3_0 } from '@swagger-api/apidom-ns-openapi-3-0' ;
13
+ import { refractorPluginReplaceEmptyElement as refractorPluginReplaceEmptyElementOpenAPI3_1 } from '@swagger-api/apidom-ns-openapi-3-1' ;
20
14
import { TextDocument } from 'vscode-languageserver-textdocument' ;
21
15
import { ParseResultElement } from '@swagger-api/apidom-core' ;
22
16
@@ -42,36 +36,62 @@ export async function parse(
42
36
let result ;
43
37
const contentLanguage = await findNamespace ( text , defaultContentLanguage ) ;
44
38
if ( contentLanguage . namespace === 'asyncapi' && contentLanguage . format === 'JSON' ) {
45
- result = await asyncapi2Adapter . parse ( text , { sourceMap : true } ) ;
39
+ result = await asyncapi2AdapterJson . parse ( text , { sourceMap : true } ) ;
46
40
} else if ( contentLanguage . namespace === 'asyncapi' && contentLanguage . format === 'YAML' ) {
47
41
const options : Record < string , unknown > = {
48
42
sourceMap : true ,
49
43
} ;
50
44
if ( registerPlugins ) {
51
- options . refractorOpts = { plugins : [ refractorPluginReplaceEmptyElement ( ) ] } ;
45
+ options . refractorOpts = { plugins : [ refractorPluginReplaceEmptyElementAsyncAPI2 ( ) ] } ;
52
46
}
53
- result = await asyncapi2Adapter_Yaml . parse ( text , options ) ;
54
- } else if ( contentLanguage . namespace === 'openapi' && contentLanguage . format === 'JSON' ) {
55
- result = await openapi3_1Adapter . parse ( text , { sourceMap : true } ) ;
56
- } else if ( contentLanguage . namespace === 'openapi' && contentLanguage . format === 'YAML' ) {
47
+ result = await asyncapi2AdapterYaml . parse ( text , options ) ;
48
+ } else if (
49
+ contentLanguage . namespace === 'openapi' &&
50
+ contentLanguage . version ?. startsWith ( '3.0' ) &&
51
+ contentLanguage . format === 'JSON'
52
+ ) {
53
+ result = await openapi3_0AdapterJson . parse ( text , { sourceMap : true } ) ;
54
+ } else if (
55
+ contentLanguage . namespace === 'openapi' &&
56
+ contentLanguage . version ?. startsWith ( '3.0' ) &&
57
+ contentLanguage . format === 'YAML'
58
+ ) {
57
59
const options : Record < string , unknown > = {
58
60
sourceMap : true ,
59
61
} ;
60
62
if ( registerPlugins ) {
61
- options . refractorOpts = { plugins : [ refractorPluginReplaceEmptyElementOas ( ) ] } ;
63
+ options . refractorOpts = { plugins : [ refractorPluginReplaceEmptyElementOpenAPI3_0 ( ) ] } ;
62
64
}
63
- result = await openapi3_1Adapter_Yaml . parse ( text , options ) ;
65
+ result = await openapi3_0AdapterYaml . parse ( text , { sourceMap : true } ) ;
66
+ } else if (
67
+ contentLanguage . namespace === 'openapi' &&
68
+ contentLanguage . version ?. startsWith ( '3.1' ) &&
69
+ contentLanguage . format === 'JSON'
70
+ ) {
71
+ result = await openapi3_1AdapterJson . parse ( text , { sourceMap : true } ) ;
72
+ } else if (
73
+ contentLanguage . namespace === 'openapi' &&
74
+ contentLanguage . version ?. startsWith ( '3.1' ) &&
75
+ contentLanguage . format === 'YAML'
76
+ ) {
77
+ const options : Record < string , unknown > = {
78
+ sourceMap : true ,
79
+ } ;
80
+ if ( registerPlugins ) {
81
+ options . refractorOpts = { plugins : [ refractorPluginReplaceEmptyElementOpenAPI3_1 ( ) ] } ;
82
+ }
83
+ result = await openapi3_1AdapterYaml . parse ( text , options ) ;
64
84
} else if ( contentLanguage . namespace === 'ads' && contentLanguage . format === 'JSON' ) {
65
- result = await adsAdapter . parse ( text , { sourceMap : true } ) ;
85
+ result = await adsAdapterJson . parse ( text , { sourceMap : true } ) ;
66
86
} else if ( contentLanguage . namespace === 'ads' && contentLanguage . format === 'YAML' ) {
67
- result = await adsAdapter_Yaml . parse ( text , { sourceMap : true } ) ;
87
+ result = await adsAdapterYaml . parse ( text , { sourceMap : true } ) ;
68
88
} else if ( contentLanguage . namespace === 'apidom' && contentLanguage . format === 'JSON' ) {
69
- result = await jsonParserAdapter . parse ( text , { sourceMap : true } ) ;
89
+ result = await adapterJson . parse ( text , { sourceMap : true } ) ;
70
90
} else if ( contentLanguage . namespace === 'apidom' && contentLanguage . format === 'YAML' ) {
71
- result = await yamlParserAdapter . parse ( text , { sourceMap : true } ) ;
91
+ result = await adapterYaml . parse ( text , { sourceMap : true } ) ;
72
92
} else {
73
93
// fallback
74
- result = await jsonParserAdapter . parse ( text , { sourceMap : true } ) ;
94
+ result = await adapterJson . parse ( text , { sourceMap : true } ) ;
75
95
}
76
96
const { api } = result ;
77
97
if ( api === undefined ) return result ;
0 commit comments