Skip to content

Commit 66ccf74

Browse files
Copilotbaywet
andcommitted
Complete OpenApiSchemaReference annotations implementation
- Add comprehensive integration test for parsing schema references with annotations - Verify full round-trip functionality works correctly - All existing tests pass (854/858 tests successful) - New serialization tests show correct behavior for v3.0 and v3.1 Co-authored-by: baywet <[email protected]>
1 parent 73ec5a7 commit 66ccf74

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

test/Microsoft.OpenApi.Tests/Models/References/OpenApiSchemaReferenceTests.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Globalization;
66
using System.IO;
77
using System.Linq;
8+
using System.Net.Http;
89
using System.Text.Json.Nodes;
910
using System.Threading.Tasks;
1011
using 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

Comments
 (0)