@@ -44,6 +44,81 @@ public void ParseCustomExtension()
4444 Assert . Equal ( "hey" , fooExtension . Bar ) ;
4545 Assert . Equal ( "hi!" , fooExtension . Baz ) ;
4646 }
47+
48+ [ Fact ]
49+ public void ExtensionParserThrowingOpenApiException_V2_ShouldHaveCorrectPointer ( )
50+ {
51+ var json = """
52+ {
53+ "swagger": "2.0",
54+ "info": {
55+ "title": "Demo",
56+ "version": "1"
57+ },
58+ "paths": {},
59+ "definitions": {
60+ "demo": {
61+ "x-tag": null
62+ }
63+ }
64+ }
65+ """ ;
66+ var settings = new OpenApiReaderSettings
67+ {
68+ ExtensionParsers =
69+ {
70+ { "x-tag" , ( any , version ) => throw new OpenApiException ( "Testing" ) }
71+ }
72+ } ;
73+
74+ var result = OpenApiDocument . Parse ( json , "json" , settings ) ;
75+
76+ Assert . NotNull ( result . Diagnostic ) ;
77+ Assert . NotEmpty ( result . Diagnostic . Errors ) ;
78+ var error = result . Diagnostic . Errors [ 0 ] ;
79+ Assert . Equal ( "Testing" , error . Message ) ;
80+ Assert . Equal ( "#/definitions/demo/x-tag" , error . Pointer ) ;
81+ }
82+
83+ [ Theory ]
84+ [ InlineData ( "3.0.4" ) ]
85+ [ InlineData ( "3.1.1" ) ]
86+ [ InlineData ( "3.2.0" ) ]
87+ public void ExtensionParserThrowingOpenApiException_V3_ShouldHaveCorrectPointer ( string version )
88+ {
89+ var json = $$ """
90+ {
91+ "openapi": "{{ version }} ",
92+ "info": {
93+ "title": "Demo",
94+ "version": "1"
95+ },
96+ "paths": {},
97+ "components": {
98+ "schemas": {
99+ "demo": {
100+ "x-tag": null
101+ }
102+ }
103+ }
104+ }
105+ """ ;
106+ var settings = new OpenApiReaderSettings
107+ {
108+ ExtensionParsers =
109+ {
110+ { "x-tag" , ( any , version ) => throw new OpenApiException ( "Testing" ) }
111+ }
112+ } ;
113+
114+ var result = OpenApiDocument . Parse ( json , "json" , settings ) ;
115+
116+ Assert . NotNull ( result . Diagnostic ) ;
117+ Assert . NotEmpty ( result . Diagnostic . Errors ) ;
118+ var error = result . Diagnostic . Errors [ 0 ] ;
119+ Assert . Equal ( "Testing" , error . Message ) ;
120+ Assert . Equal ( "#/components/schemas/demo/x-tag" , error . Pointer ) ;
121+ }
47122 }
48123
49124 internal class FooExtension : IOpenApiExtension , IOpenApiElement
0 commit comments