Skip to content

Commit 193098e

Browse files
committed
Ensure OpenApiResponseTests cover terse output
1 parent 821e6b7 commit 193098e

9 files changed

+83
-80
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"description": "A complex object array response",
3+
"schema": {
4+
"type": "array",
5+
"items": {
6+
"$ref": "#/definitions/customType"
7+
}
8+
},
9+
"headers": {
10+
"X-Rate-Limit-Limit": {
11+
"description": "The number of allowed requests in the current period",
12+
"type": "integer"
13+
},
14+
"X-Rate-Limit-Reset": {
15+
"description": "The number of seconds left in the current period",
16+
"type": "integer"
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"description":"A complex object array response","schema":{"type":"array","items":{"$ref":"#/definitions/customType"}},"headers":{"X-Rate-Limit-Limit":{"description":"The number of allowed requests in the current period","type":"integer"},"X-Rate-Limit-Reset":{"description":"The number of seconds left in the current period","type":"integer"}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$ref": "#/responses/example1"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$ref":"#/responses/example1"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"description": "A complex object array response",
3+
"headers": {
4+
"X-Rate-Limit-Limit": {
5+
"description": "The number of allowed requests in the current period",
6+
"schema": {
7+
"type": "integer"
8+
}
9+
},
10+
"X-Rate-Limit-Reset": {
11+
"description": "The number of seconds left in the current period",
12+
"schema": {
13+
"type": "integer"
14+
}
15+
}
16+
},
17+
"content": {
18+
"text/plain": {
19+
"schema": {
20+
"type": "array",
21+
"items": {
22+
"$ref": "#/components/schemas/customType"
23+
}
24+
}
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"description":"A complex object array response","headers":{"X-Rate-Limit-Limit":{"description":"The number of allowed requests in the current period","schema":{"type":"integer"}},"X-Rate-Limit-Reset":{"description":"The number of seconds left in the current period","schema":{"type":"integer"}}},"content":{"text/plain":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/customType"}}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$ref": "#/components/responses/example1"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$ref":"#/components/responses/example1"}

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

Lines changed: 27 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.IO;
7+
using System.Threading.Tasks;
78
using FluentAssertions;
89
using Microsoft.OpenApi.Any;
910
using Microsoft.OpenApi.Extensions;
1011
using Microsoft.OpenApi.Interfaces;
1112
using Microsoft.OpenApi.Models;
1213
using Microsoft.OpenApi.Writers;
14+
using VerifyXunit;
1315
using Xunit;
1416
using Xunit.Abstractions;
1517

1618
namespace Microsoft.OpenApi.Tests.Models
1719
{
1820
[Collection("DefaultSettings")]
21+
[UsesVerify]
1922
public class OpenApiResponseTests
2023
{
2124
public static OpenApiResponse BasicResponse = new OpenApiResponse();
@@ -279,132 +282,76 @@ public void SerializeAdvancedResponseAsV2YamlWorks()
279282
actual.Should().Be(expected);
280283
}
281284

282-
[Fact]
283-
public void SerializeReferencedResponseAsV3JsonWorks()
285+
[Theory]
286+
[InlineData(true)]
287+
[InlineData(false)]
288+
public async Task SerializeReferencedResponseAsV3JsonWorksAsync(bool produceTerseOutput)
284289
{
285290
// Arrange
286291
var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
287-
var writer = new OpenApiJsonWriter(outputStringWriter);
288-
var expected =
289-
@"{
290-
""$ref"": ""#/components/responses/example1""
291-
}";
292+
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput });
292293

293294
// Act
294295
ReferencedResponse.SerializeAsV3(writer);
295296
writer.Flush();
296297
var actual = outputStringWriter.GetStringBuilder().ToString();
297298

298299
// Assert
299-
actual = actual.MakeLineBreaksEnvironmentNeutral();
300-
expected = expected.MakeLineBreaksEnvironmentNeutral();
301-
actual.Should().Be(expected);
300+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
302301
}
303302

304-
[Fact]
305-
public void SerializeReferencedResponseAsV3JsonWithoutReferenceWorks()
303+
[Theory]
304+
[InlineData(true)]
305+
[InlineData(false)]
306+
public async Task SerializeReferencedResponseAsV3JsonWithoutReferenceWorksAsync(bool produceTerseOutput)
306307
{
307308
// Arrange
308309
var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
309-
var writer = new OpenApiJsonWriter(outputStringWriter);
310-
var expected =
311-
@"{
312-
""description"": ""A complex object array response"",
313-
""headers"": {
314-
""X-Rate-Limit-Limit"": {
315-
""description"": ""The number of allowed requests in the current period"",
316-
""schema"": {
317-
""type"": ""integer""
318-
}
319-
},
320-
""X-Rate-Limit-Reset"": {
321-
""description"": ""The number of seconds left in the current period"",
322-
""schema"": {
323-
""type"": ""integer""
324-
}
325-
}
326-
},
327-
""content"": {
328-
""text/plain"": {
329-
""schema"": {
330-
""type"": ""array"",
331-
""items"": {
332-
""$ref"": ""#/components/schemas/customType""
333-
}
334-
}
335-
}
336-
}
337-
}";
310+
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput });
338311

339312
// Act
340313
ReferencedResponse.SerializeAsV3WithoutReference(writer);
341314
writer.Flush();
342315
var actual = outputStringWriter.GetStringBuilder().ToString();
343316

344317
// Assert
345-
actual = actual.MakeLineBreaksEnvironmentNeutral();
346-
expected = expected.MakeLineBreaksEnvironmentNeutral();
347-
actual.Should().Be(expected);
318+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
348319
}
349320

350-
[Fact]
351-
public void SerializeReferencedResponseAsV2JsonWorks()
321+
[Theory]
322+
[InlineData(true)]
323+
[InlineData(false)]
324+
public async Task SerializeReferencedResponseAsV2JsonWorksAsync(bool produceTerseOutput)
352325
{
353326
// Arrange
354327
var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
355-
var writer = new OpenApiJsonWriter(outputStringWriter);
356-
var expected =
357-
@"{
358-
""$ref"": ""#/responses/example1""
359-
}";
328+
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput });
360329

361330
// Act
362331
ReferencedResponse.SerializeAsV2(writer);
363332
writer.Flush();
364333
var actual = outputStringWriter.GetStringBuilder().ToString();
365334

366335
// Assert
367-
actual = actual.MakeLineBreaksEnvironmentNeutral();
368-
expected = expected.MakeLineBreaksEnvironmentNeutral();
369-
actual.Should().Be(expected);
336+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
370337
}
371338

372-
[Fact]
373-
public void SerializeReferencedResponseAsV2JsonWithoutReferenceWorks()
339+
[Theory]
340+
[InlineData(true)]
341+
[InlineData(false)]
342+
public async Task SerializeReferencedResponseAsV2JsonWithoutReferenceWorksAsync(bool produceTerseOutput)
374343
{
375344
// Arrange
376345
var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
377-
var writer = new OpenApiJsonWriter(outputStringWriter);
378-
var expected =
379-
@"{
380-
""description"": ""A complex object array response"",
381-
""schema"": {
382-
""type"": ""array"",
383-
""items"": {
384-
""$ref"": ""#/definitions/customType""
385-
}
386-
},
387-
""headers"": {
388-
""X-Rate-Limit-Limit"": {
389-
""description"": ""The number of allowed requests in the current period"",
390-
""type"": ""integer""
391-
},
392-
""X-Rate-Limit-Reset"": {
393-
""description"": ""The number of seconds left in the current period"",
394-
""type"": ""integer""
395-
}
396-
}
397-
}";
346+
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput });
398347

399348
// Act
400349
ReferencedResponse.SerializeAsV2WithoutReference(writer);
401350
writer.Flush();
402351
var actual = outputStringWriter.GetStringBuilder().ToString();
403352

404353
// Assert
405-
actual = actual.MakeLineBreaksEnvironmentNeutral();
406-
expected = expected.MakeLineBreaksEnvironmentNeutral();
407-
actual.Should().Be(expected);
354+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
408355
}
409356
}
410357
}

0 commit comments

Comments
 (0)