55using System . Globalization ;
66using System . IO ;
77using System . Linq ;
8+ using System . Net . Http ;
89using System . Text . Json . Nodes ;
910using System . Threading . Tasks ;
1011using VerifyXunit ;
@@ -178,5 +179,88 @@ public async Task SerializeSchemaReferenceAsV3JsonWorks(bool produceTerseOutput)
178179 // Assert
179180 await Verifier . Verify ( outputStringWriter ) . UseParameters ( produceTerseOutput ) ;
180181 }
182+
183+ [ Fact ]
184+ public void ParseSchemaReferenceWithAnnotationsWorks ( )
185+ {
186+ // Arrange
187+ var jsonContent = @"{
188+ ""openapi"": ""3.1.0"",
189+ ""info"": {
190+ ""title"": ""Test API"",
191+ ""version"": ""1.0.0""
192+ },
193+ ""paths"": {
194+ ""/test"": {
195+ ""get"": {
196+ ""responses"": {
197+ ""200"": {
198+ ""description"": ""OK"",
199+ ""content"": {
200+ ""application/json"": {
201+ ""schema"": {
202+ ""$ref"": ""#/components/schemas/Pet"",
203+ ""title"": ""Pet Response Schema"",
204+ ""description"": ""A pet object returned from the API"",
205+ ""summary"": ""Pet Response"",
206+ ""deprecated"": true,
207+ ""readOnly"": true,
208+ ""writeOnly"": false,
209+ ""default"": {""name"": ""default pet""},
210+ ""examples"": [{""name"": ""example pet""}]
211+ }
212+ }
213+ }
214+ }
215+ }
216+ }
217+ }
218+ },
219+ ""components"": {
220+ ""schemas"": {
221+ ""Pet"": {
222+ ""type"": ""object"",
223+ ""title"": ""Original Pet Title"",
224+ ""description"": ""Original Pet Description"",
225+ ""properties"": {
226+ ""name"": {
227+ ""type"": ""string""
228+ }
229+ }
230+ }
231+ }
232+ }
233+ }" ;
234+
235+ // Act
236+ var readResult = OpenApiDocument . Parse ( jsonContent , "json" ) ;
237+ var document = readResult . Document ;
238+
239+ // Assert
240+ Assert . NotNull ( document ) ;
241+ Assert . Empty ( readResult . Diagnostic . Errors ) ;
242+
243+ var schema = document . Paths [ "/test" ] . Operations [ HttpMethod . Get ]
244+ . Responses [ "200" ] . Content [ "application/json" ] . Schema ;
245+
246+ Assert . IsType < OpenApiSchemaReference > ( schema ) ;
247+ var schemaRef = ( OpenApiSchemaReference ) schema ;
248+
249+ // Test that reference annotations override target values
250+ Assert . Equal ( "Pet Response Schema" , schemaRef . Title ) ;
251+ Assert . Equal ( "A pet object returned from the API" , schemaRef . Description ) ;
252+ Assert . Equal ( "Pet Response" , schemaRef . Summary ) ;
253+ Assert . True ( schemaRef . Deprecated ) ;
254+ Assert . True ( schemaRef . ReadOnly ) ;
255+ Assert . False ( schemaRef . WriteOnly ) ;
256+ Assert . NotNull ( schemaRef . Default ) ;
257+ Assert . Single ( schemaRef . Examples ) ;
258+
259+ // Test that target schema still has original values
260+ var targetSchema = schemaRef . Target ;
261+ Assert . NotNull ( targetSchema ) ;
262+ Assert . Equal ( "Original Pet Title" , targetSchema . Title ) ;
263+ Assert . Equal ( "Original Pet Description" , targetSchema . Description ) ;
264+ }
181265 }
182266}
0 commit comments