From 676cf8112dd62d4b6cbf717908c906a5211e27e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 00:03:29 +0000 Subject: [PATCH 1/2] Initial plan From 3ff777c6b5acbbc4e50cc10f98e9872f9e110d03 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 00:11:14 +0000 Subject: [PATCH 2/2] Rewrite AcceptanceTests to use JSON files and JsonNode.DeepEquals Replace manual parameter checks in minimal_api and mixed_api tests with JsonNode.DeepEquals comparison against expected JSON content files. Add v1-minimal.json and v1-mixed.json expected output files. Co-authored-by: sander1095 <7312681+sander1095@users.noreply.github.com> --- .../Content/v1-minimal.json | 86 ++++++++++ .../Content/v1-mixed.json | 157 ++++++++++++++++++ .../Transformers/AcceptanceTest.cs | 27 +-- 3 files changed, 251 insertions(+), 19 deletions(-) create mode 100644 src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-minimal.json create mode 100644 src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-mixed.json diff --git a/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-minimal.json b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-minimal.json new file mode 100644 index 00000000..5e9491ce --- /dev/null +++ b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-minimal.json @@ -0,0 +1,86 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "Test API | v1", + "description": "The API was deprecated on 01/01/2026. The API was sunset on 02/10/2026.\n\n### Links\n\n- [Version Deprecation Policy](http://my.api.com/policies/versions/deprecated.html)\n- [Version Sunset Policy](http://my.api.com/policies/versions/sunset.html)", + "version": "1.0" + }, + "servers": [ + { + "url": "http://localhost/" + } + ], + "paths": { + "/test/{id}": { + "get": { + "tags": [ + "Test" + ], + "summary": "", + "description": "", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": "integer", + "format": "int32" + } + }, + { + "name": "api-version", + "in": "query", + "description": "The requested API version", + "required": true, + "schema": { + "type": "string", + "default": "1.0" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + } + } + }, + "400": { + "description": "Bad Request" + } + } + } + } + }, + "tags": [ + { + "name": "Test" + } + ], + "x-api-versioning": [ + { + "title": "Version Deprecation Policy", + "type": "text/html", + "rel": "deprecation", + "url": "http://my.api.com/policies/versions/deprecated.html" + }, + { + "title": "Version Sunset Policy", + "type": "text/html", + "rel": "sunset", + "url": "http://my.api.com/policies/versions/sunset.html" + } + ] +} \ No newline at end of file diff --git a/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-mixed.json b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-mixed.json new file mode 100644 index 00000000..f6ec6c15 --- /dev/null +++ b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Content/v1-mixed.json @@ -0,0 +1,157 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "Test API | v1", + "description": "The API was deprecated on 01/01/2026. The API was sunset on 02/10/2026.\n\n### Links\n\n- [Version Deprecation Policy](http://my.api.com/policies/versions/deprecated.html)\n- [Version Sunset Policy](http://my.api.com/policies/versions/sunset.html)", + "version": "1.0" + }, + "servers": [ + { + "url": "http://localhost/" + } + ], + "paths": { + "/minimal/{id}": { + "get": { + "tags": [ + "Test" + ], + "summary": "", + "description": "", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": "integer", + "format": "int32" + } + }, + { + "name": "api-version", + "in": "query", + "description": "The requested API version", + "required": true, + "schema": { + "type": "string", + "default": "1.0" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + } + } + }, + "400": { + "description": "Bad Request" + } + } + } + }, + "/Test": { + "get": { + "tags": [ + "Test" + ], + "summary": "", + "description": "", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "", + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + }, + { + "name": "api-version", + "in": "query", + "description": "The requested API version", + "required": true, + "schema": { + "type": "string", + "default": "1.0" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "text/plain": { + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + }, + "application/json": { + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + }, + "text/json": { + "schema": { + "pattern": "^-?(?:0|[1-9]\\d*)$", + "type": [ + "integer", + "string" + ], + "format": "int32" + } + } + } + } + } + } + } + }, + "tags": [ + { + "name": "Test" + } + ], + "x-api-versioning": [ + { + "title": "Version Deprecation Policy", + "type": "text/html", + "rel": "deprecation", + "url": "http://my.api.com/policies/versions/deprecated.html" + }, + { + "title": "Version Sunset Policy", + "type": "text/html", + "rel": "sunset", + "url": "http://my.api.com/policies/versions/sunset.html" + } + ] +} \ No newline at end of file diff --git a/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Transformers/AcceptanceTest.cs b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Transformers/AcceptanceTest.cs index 9d780bbf..54d9822e 100644 --- a/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Transformers/AcceptanceTest.cs +++ b/src/AspNetCore/WebApi/test/Asp.Versioning.OpenApi.Tests/Transformers/AcceptanceTest.cs @@ -26,7 +26,6 @@ public async Task minimal_api_should_generate_expected_open_api_document() var builder = WebApplication.CreateBuilder(); builder.WebHost.UseTestServer(); - builder.Services.AddProblemDetails(); builder.Services.AddApiVersioning( options => AddPolicies( options ) ) .AddApiExplorer( options => options.GroupNameFormat = "'v'VVV" ) .AddOpenApi(); @@ -43,6 +42,9 @@ public async Task minimal_api_should_generate_expected_open_api_document() app.MapOpenApi().WithDocumentPerVersion(); var cancellationToken = TestContext.Current.CancellationToken; + using var stream = File.OpenRead( Path.Combine( AppContext.BaseDirectory, "Content", "v1-minimal.json" ) ); + var expected = await JsonNode.ParseAsync( stream, default, default, cancellationToken ); + await app.StartAsync( cancellationToken ); using var client = app.GetTestClient(); @@ -51,18 +53,7 @@ public async Task minimal_api_should_generate_expected_open_api_document() var actual = await client.GetFromJsonAsync( "/openapi/v1.json", cancellationToken ); // assert - actual!["info"]!["version"]!.GetValue().Should().Be( "1.0" ); - - var paths = actual["paths"]!.AsObject(); - - paths.Select( p => p.Key ).Should().Contain( "/test/{id}" ); - paths.Select( p => p.Key ).Should().NotContain( "/Test" ); - - var operation = paths["/test/{id}"]!["get"]!; - var parameters = operation["parameters"]!.AsArray(); - - parameters.Should().Contain( p => p!["name"]!.GetValue() == "id" ); - parameters.Should().Contain( p => p!["name"]!.GetValue() == "api-version" ); + JsonNode.DeepEquals( actual, expected ).Should().BeTrue(); } [Fact] @@ -124,6 +115,9 @@ public async Task mixed_api_should_generate_expected_open_api_document() app.MapOpenApi().WithDocumentPerVersion(); var cancellationToken = TestContext.Current.CancellationToken; + using var stream = File.OpenRead( Path.Combine( AppContext.BaseDirectory, "Content", "v1-mixed.json" ) ); + var expected = await JsonNode.ParseAsync( stream, default, default, cancellationToken ); + await app.StartAsync( cancellationToken ); using var client = app.GetTestClient(); @@ -132,12 +126,7 @@ public async Task mixed_api_should_generate_expected_open_api_document() var actual = await client.GetFromJsonAsync( "/openapi/v1.json", cancellationToken ); // assert - actual!["info"]!["version"]!.GetValue().Should().Be( "1.0" ); - - var paths = actual["paths"]!.AsObject(); - - paths.Select( p => p.Key ).Should().Contain( "/minimal/{id}" ); - paths.Select( p => p.Key ).Should().Contain( "/Test" ); + JsonNode.DeepEquals( actual, expected ).Should().BeTrue(); } private static ApiVersioningOptions AddPolicies( ApiVersioningOptions options )