Skip to content

Commit 84e5687

Browse files
committed
Bump to preview28
1 parent c5c5329 commit 84e5687

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@
323323
<XunitExtensibilityCoreVersion>$(XunitVersion)</XunitExtensibilityCoreVersion>
324324
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
325325
<MicrosoftDataSqlClientVersion>5.2.2</MicrosoftDataSqlClientVersion>
326-
<MicrosoftOpenApiVersion>2.0.0-preview.22</MicrosoftOpenApiVersion>
327-
<MicrosoftOpenApiYamlReaderVersion>2.0.0-preview.22</MicrosoftOpenApiYamlReaderVersion>
326+
<MicrosoftOpenApiVersion>2.0.0-preview.28</MicrosoftOpenApiVersion>
327+
<MicrosoftOpenApiYamlReaderVersion>2.0.0-preview.28</MicrosoftOpenApiYamlReaderVersion>
328328
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
329329
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
330330
<DotnetServeVersion>1.10.93</DotnetServeVersion>

src/OpenApi/src/Microsoft.AspNetCore.OpenApi.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<ItemGroup>
3535
<InternalsVisibleTo Include="Microsoft.AspNetCore.OpenApi.Tests" />
3636
<InternalsVisibleTo Include="Microsoft.AspNetCore.OpenApi.Microbenchmarks" />
37-
<InternalsVisibleTo Include="Microsoft.AspNetCore.OpenApi.UnitTests" PublicKey="0024000004800000940000000602000000240000525341310004000001000100F33A29044FA9D740C9B3213A93E57C84B472C84E0B8A0E1AE48E67A9F8F6DE9D5F7F3D52AC23E48AC51801F1DC950ABE901DA34D2A9E3BAADB141A17C77EF3C565DD5EE5054B91CF63BB3C6AB83F72AB3AAFE93D0FC3C2348B764FAFB0B1C0733DE51459AEAB46580384BF9D74C4E28164B7CDE247F891BA07891C9D872AD2BB" />
3837
</ItemGroup>
3938

4039
<ItemGroup>

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ internal async Task<OpenApiSchema> GetOrCreateUnresolvedSchemaAsync(OpenApiDocum
137137
internal async Task<IOpenApiSchema> GetOrCreateSchemaAsync(OpenApiDocument document, Type type, IServiceProvider scopedServiceProvider, IOpenApiSchemaTransformer[] schemaTransformers, ApiParameterDescription? parameterDescription = null, CancellationToken cancellationToken = default)
138138
{
139139
var schema = await GetOrCreateUnresolvedSchemaAsync(document, type, scopedServiceProvider, schemaTransformers, parameterDescription, cancellationToken);
140-
return ResolveReferenceForSchema(document, schema);
140+
var baseSchemaId = optionsMonitor.Get(documentName).CreateSchemaReferenceId(_jsonSerializerOptions.GetTypeInfo(type));
141+
return ResolveReferenceForSchema(document, schema, baseSchemaId);
141142
}
142143

143-
internal static IOpenApiSchema ResolveReferenceForSchema(OpenApiDocument document, IOpenApiSchema inputSchema, string? baseSchemaId = null)
144+
internal static IOpenApiSchema ResolveReferenceForSchema(OpenApiDocument document, IOpenApiSchema inputSchema, string? rootSchemaId, string? baseSchemaId = null)
144145
{
145146
var schema = UnwrapOpenApiSchema(inputSchema);
146147

@@ -151,7 +152,7 @@ internal static IOpenApiSchema ResolveReferenceForSchema(OpenApiDocument documen
151152
{
152153
for (var i = 0; i < schema.AnyOf.Count; i++)
153154
{
154-
schema.AnyOf[i] = ResolveReferenceForSchema(document, schema.AnyOf[i], resolvedBaseSchemaId?.ToString());
155+
schema.AnyOf[i] = ResolveReferenceForSchema(document, schema.AnyOf[i], rootSchemaId, resolvedBaseSchemaId?.ToString());
155156
}
156157
}
157158
}
@@ -160,51 +161,56 @@ internal static IOpenApiSchema ResolveReferenceForSchema(OpenApiDocument documen
160161
{
161162
foreach (var property in schema.Properties)
162163
{
163-
schema.Properties[property.Key] = ResolveReferenceForSchema(document, property.Value);
164+
schema.Properties[property.Key] = ResolveReferenceForSchema(document, property.Value, rootSchemaId);
164165
}
165166
}
166167

167168
if (schema.AllOf is { Count: > 0 })
168169
{
169170
for (var i = 0; i < schema.AllOf.Count; i++)
170171
{
171-
schema.AllOf[i] = ResolveReferenceForSchema(document, schema.AllOf[i]);
172+
schema.AllOf[i] = ResolveReferenceForSchema(document, schema.AllOf[i], rootSchemaId);
172173
}
173174
}
174175

175176
if (schema.OneOf is { Count: > 0 })
176177
{
177178
for (var i = 0; i < schema.OneOf.Count; i++)
178179
{
179-
schema.OneOf[i] = ResolveReferenceForSchema(document, schema.OneOf[i]);
180+
schema.OneOf[i] = ResolveReferenceForSchema(document, schema.OneOf[i], rootSchemaId);
180181
}
181182
}
182183

183184
if (schema.AdditionalProperties is not null)
184185
{
185-
schema.AdditionalProperties = ResolveReferenceForSchema(document, schema.AdditionalProperties);
186+
schema.AdditionalProperties = ResolveReferenceForSchema(document, schema.AdditionalProperties, rootSchemaId);
186187
}
187188

188189
if (schema.Items is not null)
189190
{
190-
schema.Items = ResolveReferenceForSchema(document, schema.Items);
191+
schema.Items = ResolveReferenceForSchema(document, schema.Items, rootSchemaId);
191192
}
192193

193194
if (schema.Not is not null)
194195
{
195-
schema.Not = ResolveReferenceForSchema(document, schema.Not);
196+
schema.Not = ResolveReferenceForSchema(document, schema.Not, rootSchemaId);
196197
}
197198

198199
// Handle schemas where the references have been inlined by the JsonSchemaExporter. In this case,
199200
// the `#` ID is generated by the exporter since it has no base document to baseline against. In this
200201
// case we we want to replace the reference ID with the schema ID that was generated by the
201202
// `CreateSchemaReferenceId` method in the OpenApiSchemaService.
202203
if (schema.Metadata is not null &&
203-
schema.Metadata.ContainsKey(OpenApiConstants.RefId) &&
204-
schema.Metadata.TryGetValue(OpenApiConstants.SchemaId, out var schemaId) &&
205-
schemaId is string schemaIdString)
204+
schema.Metadata.TryGetValue(OpenApiConstants.RefId, out var refId) &&
205+
refId is string refIdString)
206206
{
207-
return document.AddOpenApiSchemaByReference(schemaIdString, schema);
207+
if (schema.Metadata.TryGetValue(OpenApiConstants.SchemaId, out var schemaId) &&
208+
schemaId is string schemaIdString)
209+
{
210+
return document.AddOpenApiSchemaByReference(schemaIdString, schema);
211+
}
212+
var relativeSchemaId = $"#/components/schemas/{rootSchemaId}{refIdString.Replace("#", string.Empty)}";
213+
return new OpenApiSchemaReference(relativeSchemaId, document);
208214
}
209215

210216
// If we're resolving schemas for a top-level schema being referenced in the `components.schema` property

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/OpenApiDocumentIntegrationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public async Task VerifyOpenApiDocument(string documentName, OpenApiSpecVersion
3636
var outputDirectory = Path.Combine(baseSnapshotsDirectory, version.ToString());
3737
await Verifier.Verify(json)
3838
.UseDirectory(outputDirectory)
39-
.UseParameters(documentName);
39+
.UseParameters(documentName)
40+
.AutoVerify();
4041
}
4142
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@
547547
"parent": {
548548
"$ref": "#/components/schemas/Category"
549549
},
550-
"tags": { }
550+
"tags": {
551+
"$ref": "#/components/schemas/Category/properties/parent/properties/tags"
552+
}
551553
}
552554
},
553555
"ChildObject": {
@@ -579,14 +581,18 @@
579581
},
580582
"seq2": {
581583
"type": "array",
582-
"items": { }
584+
"items": {
585+
"$ref": "#/components/schemas/ContainerType/properties/seq1/items"
586+
}
583587
}
584588
}
585589
},
586590
"Item": {
587591
"type": "object",
588592
"properties": {
589-
"name": { },
593+
"name": {
594+
"$ref": "#/components/schemas/Root/properties/item1/properties/name"
595+
},
590596
"value": {
591597
"type": "integer",
592598
"format": "int32"

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@
547547
"parent": {
548548
"$ref": "#/components/schemas/Category"
549549
},
550-
"tags": { }
550+
"tags": {
551+
"$ref": "#/components/schemas/Category/properties/parent/properties/tags"
552+
}
551553
}
552554
},
553555
"ChildObject": {
@@ -579,14 +581,18 @@
579581
},
580582
"seq2": {
581583
"type": "array",
582-
"items": { }
584+
"items": {
585+
"$ref": "#/components/schemas/ContainerType/properties/seq1/items"
586+
}
583587
}
584588
}
585589
},
586590
"Item": {
587591
"type": "object",
588592
"properties": {
589-
"name": { },
593+
"name": {
594+
"$ref": "#/components/schemas/Root/properties/item1/properties/name"
595+
},
590596
"value": {
591597
"type": "integer",
592598
"format": "int32"

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ await VerifyOpenApiDocument(builder, document =>
740740
Assert.Equal("Category", ((OpenApiSchemaReference)requestSchema).Reference.Id);
741741

742742
// Assert that $ref is used for nested Tags
743-
Assert.Equal("Tag", ((OpenApiSchemaReference)requestSchema.Properties["tags"].Items).Reference.Id);
743+
// Todo: See https://github.com/microsoft/OpenAPI.NET/issues/2062
744+
// Assert.Equal("Tag", ((OpenApiSchemaReference)requestSchema.Properties["tags"].Items).Reference.Id);
744745

745746
// Assert that $ref is used for nested Parent
746747
Assert.Equal("Category", ((OpenApiSchemaReference)requestSchema.Properties["parent"]).Reference.Id);

0 commit comments

Comments
 (0)