88using Microsoft . OpenApi . Exceptions ;
99using Microsoft . OpenApi . Interfaces ;
1010using Microsoft . OpenApi . Models ;
11+ using Microsoft . OpenApi . Readers . Exceptions ;
1112using SharpYaml . Serialization ;
1213
1314namespace Microsoft . OpenApi . Readers . ParseNodes
@@ -26,26 +27,23 @@ protected ParseNode(ParsingContext parsingContext, OpenApiDiagnostic diagnostic)
2627
2728 public MapNode CheckMapNode ( string nodeName )
2829 {
29- var mapNode = this as MapNode ;
30- if ( mapNode == null )
30+ if ( ! ( this is MapNode mapNode ) )
3131 {
32- throw new OpenApiException ( $ "{ nodeName } must be a map/object") ;
32+ throw new OpenApiReaderException ( $ "{ nodeName } must be a map/object") ;
3333 }
3434
3535 return mapNode ;
3636 }
3737
3838 public static ParseNode Create ( ParsingContext context , OpenApiDiagnostic diagnostic , YamlNode node )
3939 {
40- var listNode = node as YamlSequenceNode ;
4140
42- if ( listNode != null )
41+ if ( node is YamlSequenceNode listNode )
4342 {
4443 return new ListNode ( context , diagnostic , listNode ) ;
4544 }
4645
47- var mapNode = node as YamlMappingNode ;
48- if ( mapNode != null )
46+ if ( node is YamlMappingNode mapNode )
4947 {
5048 return new MapNode ( context , diagnostic , mapNode ) ;
5149 }
@@ -55,50 +53,50 @@ public static ParseNode Create(ParsingContext context, OpenApiDiagnostic diagnos
5553
5654 public virtual List < T > CreateList < T > ( Func < MapNode , T > map )
5755 {
58- throw new OpenApiException ( "Cannot create list from this type of node." ) ;
56+ throw new OpenApiReaderException ( "Cannot create list from this type of node." ) ;
5957 }
6058
6159 public virtual Dictionary < string , T > CreateMap < T > ( Func < MapNode , T > map )
6260 {
63- throw new OpenApiException ( "Cannot create map from this type of node." ) ;
61+ throw new OpenApiReaderException ( "Cannot create map from this type of node." ) ;
6462 }
6563
6664 public virtual Dictionary < string , T > CreateMapWithReference < T > (
6765 ReferenceType referenceType ,
6866 Func < MapNode , T > map )
6967 where T : class , IOpenApiReferenceable
7068 {
71- throw new OpenApiException ( "Cannot create map from this reference." ) ;
69+ throw new OpenApiReaderException ( "Cannot create map from this reference." ) ;
7270 }
7371
7472 public virtual List < T > CreateSimpleList < T > ( Func < ValueNode , T > map )
7573 {
76- throw new OpenApiException ( "Cannot create simple list from this type of node." ) ;
74+ throw new OpenApiReaderException ( "Cannot create simple list from this type of node." ) ;
7775 }
7876
7977 public virtual Dictionary < string , T > CreateSimpleMap < T > ( Func < ValueNode , T > map )
8078 {
81- throw new OpenApiException ( "Cannot create simple map from this type of node." ) ;
79+ throw new OpenApiReaderException ( "Cannot create simple map from this type of node." ) ;
8280 }
8381
8482 public virtual IOpenApiAny CreateAny ( )
8583 {
86- throw new OpenApiException ( "Cannot create an Any object this type of node." ) ;
84+ throw new OpenApiReaderException ( "Cannot create an Any object this type of node." ) ;
8785 }
8886
8987 public virtual string GetRaw ( )
9088 {
91- throw new OpenApiException ( "Cannot get raw value from this type of node." ) ;
89+ throw new OpenApiReaderException ( "Cannot get raw value from this type of node." ) ;
9290 }
9391
9492 public virtual string GetScalarValue ( )
9593 {
96- throw new OpenApiException ( "Cannot create a scalar value from this type of node." ) ;
94+ throw new OpenApiReaderException ( "Cannot create a scalar value from this type of node." ) ;
9795 }
9896
9997 public virtual List < IOpenApiAny > CreateListOfAny ( )
10098 {
101- throw new OpenApiException ( "Cannot create a list from this type of node." ) ;
99+ throw new OpenApiReaderException ( "Cannot create a list from this type of node." ) ;
102100 }
103101
104102 }
0 commit comments