Skip to content

Commit 94aad3e

Browse files
Upgrade to Microsoft.OpenApi v2
Upgrade to preview 5 of Microsoft.OpenApi v2. Lots of tests are broken. Also applies some refactorings in files that needed to be touched, but those will be extracted out and merged ahead of time where possible in a future PR.
1 parent fcfcdd6 commit 94aad3e

81 files changed

Lines changed: 943 additions & 914 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.32" />
2222
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
2323
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.0" />
24-
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.22" />
25-
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
24+
<PackageVersion Include="Microsoft.OpenApi" Version="2.0.0-preview5" />
25+
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="2.0.0-preview5" />
2626
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2727
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2828
<PackageVersion Include="NSubstitute" Version="5.3.0" />
2929
<PackageVersion Include="NSwag.MSBuild" Version="14.2.0" />
3030
<PackageVersion Include="ReportGenerator" Version="5.4.1" />
31-
<PackageVersion Include="System.Text.Json" Version="4.6.0" />
31+
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
3232
<PackageVersion Include="Verify.Xunit" Version="28.3.2" />
3333
<PackageVersion Include="xunit" Version="2.9.2" />
3434
<PackageVersion Include="xunit.core" Version="2.9.2" />

perf/Swashbuckle.AspNetCore.Benchmarks/XmlCommentsBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void Setup()
101101
{
102102
Schema = new()
103103
{
104-
Type = "string",
104+
Type = JsonSchemaType.String,
105105
Description = "schema-level description",
106106
},
107107
};
@@ -120,7 +120,7 @@ public void Setup()
120120
{
121121
Schema = new()
122122
{
123-
Type = "string",
123+
Type = JsonSchemaType.String,
124124
},
125125
},
126126
},

src/Swashbuckle.AspNetCore.Annotations/AnnotationsOperationFilter.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ private static void ApplySwaggerOperationAttribute(
6363
if (swaggerOperationAttribute.OperationId != null)
6464
operation.OperationId = swaggerOperationAttribute.OperationId;
6565

66-
if (swaggerOperationAttribute.Tags != null)
67-
{
68-
operation.Tags = swaggerOperationAttribute.Tags
69-
.Select(tagName => new OpenApiTag { Name = tagName })
70-
.ToList();
71-
}
66+
// TODO Fix this
67+
////if (swaggerOperationAttribute.Tags != null)
68+
////{
69+
//// operation.Tags = swaggerOperationAttribute.Tags
70+
//// .Select(tagName => new OpenApiTag { Name = tagName })
71+
//// .ToList();
72+
////}
7273
}
7374

7475
public static void ApplySwaggerOperationFilterAttributes(

src/Swashbuckle.AspNetCore.ApiTesting/ApiTestRunnerBase.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
using System.Net.Http;
44
using System.Threading.Tasks;
55
using Microsoft.OpenApi.Models;
6+
using Microsoft.OpenApi.Reader;
7+
using Microsoft.OpenApi.Readers;
68
using Microsoft.OpenApi.Writers;
79

810
namespace Swashbuckle.AspNetCore.ApiTesting
911
{
1012
public abstract class ApiTestRunnerBase : IDisposable
1113
{
14+
static ApiTestRunnerBase()
15+
{
16+
// TODO Make an assembly fixture
17+
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
18+
}
19+
1220
private readonly ApiTestRunnerOptions _options;
1321
private readonly RequestValidator _requestValidator;
1422
private readonly ResponseValidator _responseValidator;
@@ -85,4 +93,4 @@ public void Dispose()
8593
}
8694
}
8795
}
88-
}
96+
}

src/Swashbuckle.AspNetCore.ApiTesting/ApiTestRunnerOptionsExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using Microsoft.OpenApi.Models;
4-
using Microsoft.OpenApi.Readers;
54

65
namespace Swashbuckle.AspNetCore.ApiTesting
76
{
@@ -10,9 +9,12 @@ public static class ApiTestRunnerOptionsExtensions
109
public static void AddOpenApiFile(this ApiTestRunnerOptions options, string documentName, string filePath)
1110
{
1211
using var fileStream = File.OpenRead(filePath);
12+
using var memoryStream = new MemoryStream();
1313

14-
var openApiDocument = new OpenApiStreamReader().Read(fileStream, out var diagnostic);
15-
options.OpenApiDocs.Add(documentName, openApiDocument);
14+
fileStream.CopyTo(memoryStream);
15+
16+
var result = OpenApiDocument.Load(memoryStream);
17+
options.OpenApiDocs.Add(documentName, result.Document);
1618
}
1719

1820
public static OpenApiDocument GetOpenApiDocument(this ApiTestRunnerOptions options, string documentName)

src/Swashbuckle.AspNetCore.ApiTesting/JsonContentValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Swashbuckle.AspNetCore.ApiTesting
88
{
9-
public class JsonContentValidator : IContentValidator
9+
public sealed class JsonContentValidator : IContentValidator
1010
{
1111
private readonly JsonValidator _jsonValidator = new();
1212

src/Swashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonAllOfValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace Swashbuckle.AspNetCore.ApiTesting
77
{
8-
public class JsonAllOfValidator(JsonValidator jsonValidator) : IJsonValidator
8+
public sealed class JsonAllOfValidator(JsonValidator jsonValidator) : IJsonValidator
99
{
10-
private JsonValidator _jsonValidator = jsonValidator;
10+
private readonly JsonValidator _jsonValidator = jsonValidator;
1111

1212
public bool CanValidate(OpenApiSchema schema) => schema.AllOf != null && schema.AllOf.Any();
1313

src/Swashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonAnyOfValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace Swashbuckle.AspNetCore.ApiTesting
77
{
8-
public class JsonAnyOfValidator(JsonValidator jsonValidator) : IJsonValidator
8+
public sealed class JsonAnyOfValidator(JsonValidator jsonValidator) : IJsonValidator
99
{
10-
private JsonValidator _jsonValidator = jsonValidator;
10+
private readonly JsonValidator _jsonValidator = jsonValidator;
1111

1212
public bool CanValidate(OpenApiSchema schema) => schema.AnyOf != null && schema.AnyOf.Any();
1313

src/Swashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonArrayValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class JsonArrayValidator(IJsonValidator jsonValidator) : IJsonValidator
99
{
1010
private readonly IJsonValidator _jsonValidator = jsonValidator;
1111

12-
public bool CanValidate(OpenApiSchema schema) => schema.Type == "array";
12+
public bool CanValidate(OpenApiSchema schema) => schema.Type is JsonSchemaType.Array;
1313

1414
public bool Validate(
1515
OpenApiSchema schema,

src/Swashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonBooleanValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Swashbuckle.AspNetCore.ApiTesting
66
{
7-
public class JsonBooleanValidator : IJsonValidator
7+
public sealed class JsonBooleanValidator : IJsonValidator
88
{
9-
public bool CanValidate(OpenApiSchema schema) => schema.Type == "boolean";
9+
public bool CanValidate(OpenApiSchema schema) => schema.Type is JsonSchemaType.Boolean;
1010

1111
public bool Validate(
1212
OpenApiSchema schema,

0 commit comments

Comments
 (0)