@@ -54,78 +54,81 @@ public AsyncApiReference ConvertToAsyncApiReference(
5454 string reference ,
5555 ReferenceType ? type )
5656 {
57- if ( ! string . IsNullOrWhiteSpace ( reference ) )
57+ if ( string . IsNullOrWhiteSpace ( reference ) )
5858 {
59- var segments = reference . Split ( '#' ) ;
60- if ( segments . Length == 1 )
59+ throw new AsyncApiException ( $ "The reference string '{ reference } ' has invalid format.") ;
60+ }
61+
62+ var segments = reference . Split ( '#' ) ;
63+ if ( segments . Length == 1 )
64+ {
65+ if ( type == ReferenceType . SecurityScheme )
6166 {
62- if ( type == ReferenceType . SecurityScheme )
67+ return new AsyncApiReference
6368 {
64- return new AsyncApiReference
65- {
66- Type = type ,
67- Id = reference ,
68- } ;
69- }
69+ Type = type ,
70+ Id = reference ,
71+ } ;
72+ }
7073
71- var asyncApiReference = new AsyncApiReference ( ) ;
72- if ( reference . StartsWith ( "/" ) )
73- {
74- asyncApiReference . IsFragment = true ;
75- }
74+ var asyncApiReference = new AsyncApiReference ( ) ;
75+ asyncApiReference . Type = type ;
76+ if ( reference . StartsWith ( "/" ) )
77+ {
78+ asyncApiReference . IsFragment = true ;
79+ }
7680
77- asyncApiReference . ExternalResource = segments [ 0 ] ;
81+ asyncApiReference . ExternalResource = segments [ 0 ] ;
7882
79- return asyncApiReference ;
83+ return asyncApiReference ;
8084
81- }
82- else if ( segments . Length == 2 )
85+ }
86+ else if ( segments . Length == 2 )
87+ {
88+ // Local reference
89+ if ( reference . StartsWith ( "#" ) )
8390 {
84- // Local reference
85- if ( reference . StartsWith ( "#" ) )
91+ try
8692 {
87- try
88- {
89- return this . ParseReference ( segments [ 1 ] ) ;
90- }
91- catch ( AsyncApiException ex )
92- {
93- this . Diagnostic . Errors . Add ( new AsyncApiError ( ex ) ) ;
94- return null ;
95- }
93+ return this . ParseReference ( segments [ 1 ] ) ;
9694 }
97-
98- var id = segments [ 1 ] ;
99- var asyncApiReference = new AsyncApiReference ( ) ;
100- if ( id . StartsWith ( "/components/" ) )
95+ catch ( AsyncApiException ex )
10196 {
102- var localSegments = segments [ 1 ] . Split ( '/' ) ;
103- var referencedType = localSegments [ 2 ] . GetEnumFromDisplayName < ReferenceType > ( ) ;
104- if ( type == null )
105- {
106- type = referencedType ;
107- }
108- else
109- {
110- if ( type != referencedType )
111- {
112- throw new AsyncApiException ( "Referenced type mismatch" ) ;
113- }
114- }
97+ this . Diagnostic . Errors . Add ( new AsyncApiError ( ex ) ) ;
98+ return null ;
99+ }
100+ }
115101
116- id = localSegments [ 3 ] ;
102+ var id = segments [ 1 ] ;
103+ var asyncApiReference = new AsyncApiReference ( ) ;
104+ if ( id . StartsWith ( "/components/" ) )
105+ {
106+ var localSegments = segments [ 1 ] . Split ( '/' ) ;
107+ var referencedType = localSegments [ 2 ] . GetEnumFromDisplayName < ReferenceType > ( ) ;
108+ if ( type == null )
109+ {
110+ type = referencedType ;
117111 }
118112 else
119113 {
120- asyncApiReference . IsFragment = true ;
114+ if ( type != referencedType )
115+ {
116+ throw new AsyncApiException ( "Referenced type mismatch" ) ;
117+ }
121118 }
122119
123- asyncApiReference . ExternalResource = segments [ 0 ] ;
124- asyncApiReference . Type = type ;
125- asyncApiReference . Id = id ;
126-
127- return asyncApiReference ;
120+ id = localSegments [ 3 ] ;
128121 }
122+ else
123+ {
124+ asyncApiReference . IsFragment = true ;
125+ }
126+
127+ asyncApiReference . ExternalResource = segments [ 0 ] ;
128+ asyncApiReference . Type = type ;
129+ asyncApiReference . Id = id ;
130+
131+ return asyncApiReference ;
129132 }
130133
131134 throw new AsyncApiException ( $ "The reference string '{ reference } ' has invalid format.") ;
0 commit comments