Skip to content

Commit d85a810

Browse files
committed
Clean up logic Update tests
1 parent d587137 commit d85a810

7 files changed

+19
-57
lines changed

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Microsoft.OpenApi.Interfaces;
8+
using Microsoft.OpenApi.Models.References;
89
using Microsoft.OpenApi.Writers;
910

1011
namespace Microsoft.OpenApi.Models
@@ -256,18 +257,13 @@ public void SerializeAsV2(IOpenApiWriter writer)
256257
}
257258
else if (RequestBody.Reference != null)
258259
{
260+
var hostDocument = RequestBody.Reference.HostDocument;
259261
parameters.Add(
260-
new()
261-
{
262-
UnresolvedReference = true,
263-
Reference = RequestBody.Reference
264-
});
262+
new OpenApiParameterReference(RequestBody.Reference.Id, hostDocument));
265263

266-
if (RequestBody.Reference.HostDocument != null)
267-
{
268-
var effectiveRequestBody = RequestBody.GetEffective(RequestBody.Reference.HostDocument);
269-
if (effectiveRequestBody != null)
270-
consumes = effectiveRequestBody.Content.Keys.Distinct().ToList();
264+
if (hostDocument != null)
265+
{
266+
consumes = RequestBody.Content.Keys.Distinct().ToList();
271267
}
272268
}
273269

@@ -291,7 +287,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
291287
.Concat(
292288
Responses
293289
.Where(static r => r.Value.Reference is {HostDocument: not null})
294-
.SelectMany(static r => r.Value.GetEffective(r.Value.Reference.HostDocument)?.Content?.Keys))
290+
.SelectMany(static r => r.Value.Content?.Keys))
295291
.Distinct()
296292
.ToList();
297293

src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override string Description
7575
}
7676

7777
/// <inheritdoc/>
78-
public override IDictionary<string, OpenApiMediaType> Content { get => Target.Content; set => Target.Content = value; }
78+
public override IDictionary<string, OpenApiMediaType> Content { get => Target?.Content; set => Target.Content = value; }
7979

8080
/// <inheritdoc/>
8181
public override IDictionary<string, OpenApiHeader> Headers { get => Target.Headers; set => Target.Headers = value; }

test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
55
using FluentAssertions;
66
using Json.Schema;
77
using Microsoft.OpenApi.Extensions;
88
using Microsoft.OpenApi.Models;
9+
using Microsoft.OpenApi.Models.References;
910
using Xunit;
1011

1112
namespace Microsoft.OpenApi.Tests.Models
@@ -52,14 +53,7 @@ public class OpenApiOperationTests
5253
},
5354
Responses = new()
5455
{
55-
["200"] = new()
56-
{
57-
Reference = new()
58-
{
59-
Id = "response1",
60-
Type = ReferenceType.Response
61-
}
62-
},
56+
["200"] = new OpenApiResponseReference("response1", hostDocument: null),
6357
["400"] = new()
6458
{
6559
Content = new Dictionary<string, OpenApiMediaType>
@@ -90,14 +84,7 @@ public class OpenApiOperationTests
9084
Name = "tagName1",
9185
Description = "tagDescription1",
9286
},
93-
new()
94-
{
95-
Reference = new()
96-
{
97-
Id = "tagId1",
98-
Type = ReferenceType.Tag
99-
}
100-
}
87+
new OpenApiTagReference("tagId1", null)
10188
},
10289
Summary = "summary1",
10390
Description = "operationDescription",
@@ -134,14 +121,7 @@ public class OpenApiOperationTests
134121
},
135122
Responses = new()
136123
{
137-
["200"] = new()
138-
{
139-
Reference = new()
140-
{
141-
Id = "response1",
142-
Type = ReferenceType.Response
143-
}
144-
},
124+
["200"] = new OpenApiResponseReference("response1", hostDocument: null),
145125
["400"] = new()
146126
{
147127
Content = new Dictionary<string, OpenApiMediaType>
@@ -157,22 +137,8 @@ public class OpenApiOperationTests
157137
{
158138
new()
159139
{
160-
[new()
161-
{
162-
Reference = new()
163-
{
164-
Id = "securitySchemeId1",
165-
Type = ReferenceType.SecurityScheme
166-
}
167-
}] = new List<string>(),
168-
[new()
169-
{
170-
Reference = new()
171-
{
172-
Id = "securitySchemeId2",
173-
Type = ReferenceType.SecurityScheme
174-
}
175-
}] = new List<string>
140+
[new OpenApiSecuritySchemeReference("securitySchemeId1", hostDocument: null)] = new List<string>(),
141+
[new OpenApiSecuritySchemeReference("securitySchemeId2", hostDocument: null)] = new List<string>
176142
{
177143
"scopeName1",
178144
"scopeName2"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"description": "Location of the locally created post",
2+
"description": "The URL of the newly created post",
33
"type": "string"
44
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"description":"Location of the locally created post","type":"string"}
1+
{"description":"The URL of the newly created post","type":"string"}

test/Microsoft.OpenApi.Tests/Models/References/OpenApiParameterReferenceTests.SerializeParameterReferenceAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"in": "query",
33
"name": "limit",
4-
"description": "Results to return",
4+
"description": "Number of results to return",
55
"type": "integer",
66
"maximum": 100,
77
"minimum": 1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"in":"query","name":"limit","description":"Results to return","type":"integer","maximum":100,"minimum":1}
1+
{"in":"query","name":"limit","description":"Number of results to return","type":"integer","maximum":100,"minimum":1}

0 commit comments

Comments
 (0)