Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -51,18 +53,7 @@ public async Task minimal_api_should_generate_expected_open_api_document()
var actual = await client.GetFromJsonAsync<JsonNode>( "/openapi/v1.json", cancellationToken );

// assert
actual!["info"]!["version"]!.GetValue<string>().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<string>() == "id" );
parameters.Should().Contain( p => p!["name"]!.GetValue<string>() == "api-version" );
JsonNode.DeepEquals( actual, expected ).Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -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();
Expand All @@ -132,12 +126,7 @@ public async Task mixed_api_should_generate_expected_open_api_document()
var actual = await client.GetFromJsonAsync<JsonNode>( "/openapi/v1.json", cancellationToken );

// assert
actual!["info"]!["version"]!.GetValue<string>().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 )
Expand Down