@@ -44,6 +44,80 @@ 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+ public void ExtensionParserThrowingOpenApiException_V3_ShouldHaveCorrectPointer ( string version )
87+ {
88+ var json = $$ """
89+ {
90+ "openapi": "{{ version }} ",
91+ "info": {
92+ "title": "Demo",
93+ "version": "1"
94+ },
95+ "paths": {},
96+ "components": {
97+ "schemas": {
98+ "demo": {
99+ "x-tag": null
100+ }
101+ }
102+ }
103+ }
104+ """ ;
105+ var settings = new OpenApiReaderSettings
106+ {
107+ ExtensionParsers =
108+ {
109+ { "x-tag" , ( any , version ) => throw new OpenApiException ( "Testing" ) }
110+ }
111+ } ;
112+
113+ var result = OpenApiDocument . Parse ( json , "json" , settings ) ;
114+
115+ Assert . NotNull ( result . Diagnostic ) ;
116+ Assert . NotEmpty ( result . Diagnostic . Errors ) ;
117+ var error = result . Diagnostic . Errors [ 0 ] ;
118+ Assert . Equal ( "Testing" , error . Message ) ;
119+ Assert . Equal ( "#/components/schemas/demo/x-tag" , error . Pointer ) ;
120+ }
47121 }
48122
49123 internal class FooExtension : IOpenApiExtension , IOpenApiElement
0 commit comments