Skip to content
Open
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
20 changes: 10 additions & 10 deletions .bot/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# .bot Workspace
This folder is reserved for local-only AI working material such as:
- brainstorm notes
- draft implementation plans
- design alternatives
- temporary agent state
Keep this folder out of source control. Move only finalized, non-confidential guidance into `AGENTS.md`.
# .bot Workspace

This folder is reserved for local-only AI working material such as:

- brainstorm notes
- draft implementation plans
- design alternatives
- temporary agent state

Keep this folder out of source control. Move only finalized, non-confidential guidance into `AGENTS.md`.
8 changes: 4 additions & 4 deletions .docfx/BuildDocfxImage.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version = minver -i -t v -v w
docfx metadata docfx.json
docker buildx build -t jcr.codebelt.net/geekle/asp-versioning-docfx:$version --platform linux/arm64,linux/amd64 --load -f Dockerfile.docfx .
get-childItem -recurse -path api -include *.yml, .manifest | remove-item
$version = minver -i -t v -v w
docfx metadata docfx.json
docker buildx build -t jcr.codebelt.net/geekle/asp-versioning-docfx:$version --platform linux/arm64,linux/amd64 --load -f Dockerfile.docfx .
get-childItem -recurse -path api -include *.yml, .manifest | remove-item
32 changes: 16 additions & 16 deletions .docfx/Dockerfile.docfx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
ARG NGINX_VERSION=1.31-alpine
FROM --platform=$BUILDPLATFORM dhi.io/nginx:${NGINX_VERSION} AS base
RUN rm -rf /usr/share/nginx/html/*
FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2 AS build
ADD [".", "docfx"]
RUN cd docfx; \
docfx build
FROM dhi.io/nginx:${NGINX_VERSION} AS final
WORKDIR /usr/share/nginx/html
COPY --from=build /build/docfx/wwwroot /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
ARG NGINX_VERSION=1.31-alpine

FROM --platform=$BUILDPLATFORM dhi.io/nginx:${NGINX_VERSION} AS base
RUN rm -rf /usr/share/nginx/html/*

FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2 AS build

ADD [".", "docfx"]

RUN cd docfx; \
docfx build

FROM dhi.io/nginx:${NGINX_VERSION} AS final
WORKDIR /usr/share/nginx/html
COPY --from=build /build/docfx/wwwroot /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
6 changes: 3 additions & 3 deletions .docfx/PublishDocfxImage.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$version = minver -i -t v -v w
docker tag asp-versioning-docfx:$version jcr.codebelt.net/geekle/asp-versioning-docfx:$version
docker push jcr.codebelt.net/geekle/asp-versioning-docfx:$version
$version = minver -i -t v -v w
docker tag asp-versioning-docfx:$version jcr.codebelt.net/geekle/asp-versioning-docfx:$version
docker push jcr.codebelt.net/geekle/asp-versioning-docfx:$version
50 changes: 25 additions & 25 deletions .docfx/api/namespaces/Codebelt.Extensions.Asp.Versioning.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
---
uid: Codebelt.Extensions.Asp.Versioning
summary: *content
---
Use this namespace when building versioned ASP.NET Core RESTful APIs that accept the API version from the HTTP `Accept` header — a common pattern for APIs consumed by real browsers and heterogeneous clients — without writing bespoke middleware to filter browser MIME types or translate Asp.Versioning error codes into structured exception types. It also provides semantic API version metadata for APIs whose public contract needs `major.minor.patch`, pre-release, and build metadata while still participating in the `Asp.Versioning.ApiVersion` model.
RESTful API versioning built on `Asp.Versioning` normally requires coordinating three separate registration calls — `AddApiVersioning`, `AddMvc`, and `AddApiExplorer` — alongside a version reader that copes with the broad range of `Accept` header values real browsers and HTTP clients send. This namespace provides a single-call registration path and a filtered media-type version reader that handles that coordination automatically.
Start with `AddRestfulApiVersioning` on `IServiceCollection`: it wires all three calls together, installs `RestfulApiVersionReader` to parse the API version from the `Accept` header while ignoring irrelevant browser MIME types, and registers problem-details integration compatible with RFC 7807. To translate Asp.Versioning status-code responses into typed `HttpStatusCodeException` values that the rest of your pipeline can handle, call `UseRestfulApiVersioning` on `IApplicationBuilder` in the middleware pipeline. Configure behaviour — default API version, parameter name, accepted media types, version selector strategy, and problem-details style — through `RestfulApiVersioningOptions`.
Use `SemanticApiVersion`, `SemanticApiVersionParser`, and the semantic version attributes when you need `Asp.Versioning` endpoints to advertise or map versions such as `1.2.3-alpha+build.5`. `SemanticApiVersion.CompareTo` follows Semantic Versioning precedence and ignores build metadata for ordering, while equality keeps build metadata as part of exact version identity. The existing RESTful API Explorer group-name format is unchanged; `SemanticApiVersionFormatter` collapses semantic endpoint versions such as `1.0.1`, `1.2.0`, and `1.2.3-alpha+build.5` to the `v1` group.
[!INCLUDE [availability-modern](../../includes/availability-modern.md)]
Complements: [Asp.Versioning](https://github.com/dotnet/aspnet-api-versioning) together with Open API/Swagger for RESTful APIs. 🔗
### Extension Members
|Type|Ext|Methods|
|--:|:-:|---|
|`IApplicationBuilder`|⬇️|`UseRestfulApiVersioning`|
|`IServiceCollection`|⬇️|`AddRestfulApiVersioning`|
|`IServiceCollection`|⬇️|`AddApiVersionParser<T>`|
Use `AddApiVersionParser` to register a custom `IApiVersionParser` — for example, an `ApiVersionAliasParser` built with `CreateSemanticVersionAlias` that maps short version tokens to canonical `SemanticApiVersion` instances.
---
uid: Codebelt.Extensions.Asp.Versioning
summary: *content
---
Use this namespace when building versioned ASP.NET Core RESTful APIs that accept the API version from the HTTP `Accept` header — a common pattern for APIs consumed by real browsers and heterogeneous clients — without writing bespoke middleware to filter browser MIME types or translate Asp.Versioning error codes into structured exception types. It also provides semantic API version metadata for APIs whose public contract needs `major.minor.patch`, pre-release, and build metadata while still participating in the `Asp.Versioning.ApiVersion` model.

RESTful API versioning built on `Asp.Versioning` normally requires coordinating three separate registration calls — `AddApiVersioning`, `AddMvc`, and `AddApiExplorer` — alongside a version reader that copes with the broad range of `Accept` header values real browsers and HTTP clients send. This namespace provides a single-call registration path and a filtered media-type version reader that handles that coordination automatically.

Start with `AddRestfulApiVersioning` on `IServiceCollection`: it wires all three calls together, installs `RestfulApiVersionReader` to parse the API version from the `Accept` header while ignoring irrelevant browser MIME types, and registers problem-details integration compatible with RFC 7807. To translate Asp.Versioning status-code responses into typed `HttpStatusCodeException` values that the rest of your pipeline can handle, call `UseRestfulApiVersioning` on `IApplicationBuilder` in the middleware pipeline. Configure behaviour — default API version, parameter name, accepted media types, version selector strategy, and problem-details style — through `RestfulApiVersioningOptions`.

Use `SemanticApiVersion`, `SemanticApiVersionParser`, and the semantic version attributes when you need `Asp.Versioning` endpoints to advertise or map versions such as `1.2.3-alpha+build.5`. `SemanticApiVersion.CompareTo` follows Semantic Versioning precedence and ignores build metadata for ordering, while equality keeps build metadata as part of exact version identity. The existing RESTful API Explorer group-name format is unchanged; `SemanticApiVersionFormatter` collapses semantic endpoint versions such as `1.0.1`, `1.2.0`, and `1.2.3-alpha+build.5` to the `v1` group.

[!INCLUDE [availability-modern](../../includes/availability-modern.md)]

Complements: [Asp.Versioning](https://github.com/dotnet/aspnet-api-versioning) together with Open API/Swagger for RESTful APIs. 🔗

### Extension Members

|Type|Ext|Methods|
|--:|:-:|---|
|`IApplicationBuilder`|⬇️|`UseRestfulApiVersioning`|
|`IServiceCollection`|⬇️|`AddRestfulApiVersioning`|
|`IServiceCollection`|⬇️|`AddApiVersionParser<T>`|

Use `AddApiVersionParser` to register a custom `IApiVersionParser` — for example, an `ApiVersionAliasParser` built with `CreateSemanticVersionAlias` that maps short version tokens to canonical `SemanticApiVersion` instances.
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
---
uid: Codebelt.Extensions.Asp.Versioning.RestfulApiVersionReader
example:
- *content
---
Use `RestfulApiVersionReader` when you need fine-grained control over which Accept media types are eligible for version parsing — for example when configuring `AddApiVersioning` directly rather than using the `AddRestfulApiVersioning` convenience method. The reader filters the incoming `Accept` header collection to only the entries whose media types start with one of the configured `validAcceptHeaders` values before delegating to `MediaTypeApiVersionReader`, which prevents browser-injected entries such as `text/html` or `image/webp` from being misread as version indicators.
```csharp
using System.Collections.Generic;
using Asp.Versioning;
using Codebelt.Extensions.Asp.Versioning;
using Microsoft.Extensions.DependencyInjection;
namespace Codebelt.Extensions.Asp.Versioning;
public class CustomVersioningSetup
{
public static void ConfigureServices(IServiceCollection services)
{
var acceptHeaders = new List<string>
{
"application/json",
"application/xml",
"text/json",
"text/xml",
"text/plain",
"*/*"
};
services.AddApiVersioning(o =>
{
o.DefaultApiVersion = new ApiVersion(1, 0);
o.AssumeDefaultVersionWhenUnspecified = true;
o.ApiVersionReader = new RestfulApiVersionReader(acceptHeaders, "v");
});
}
}
```
---
uid: Codebelt.Extensions.Asp.Versioning.RestfulApiVersionReader
example:
- *content
---
Use `RestfulApiVersionReader` when you need fine-grained control over which Accept media types are eligible for version parsing — for example when configuring `AddApiVersioning` directly rather than using the `AddRestfulApiVersioning` convenience method. The reader filters the incoming `Accept` header collection to only the entries whose media types start with one of the configured `validAcceptHeaders` values before delegating to `MediaTypeApiVersionReader`, which prevents browser-injected entries such as `text/html` or `image/webp` from being misread as version indicators.

```csharp
using System.Collections.Generic;
using Asp.Versioning;
using Codebelt.Extensions.Asp.Versioning;
using Microsoft.Extensions.DependencyInjection;

namespace Codebelt.Extensions.Asp.Versioning;

public class CustomVersioningSetup
{
public static void ConfigureServices(IServiceCollection services)
{
var acceptHeaders = new List<string>
{
"application/json",
"application/xml",
"text/json",
"text/xml",
"text/plain",
"*/*"
};

services.AddApiVersioning(o =>
{
o.DefaultApiVersion = new ApiVersion(1, 0);
o.AssumeDefaultVersionWhenUnspecified = true;
o.ApiVersionReader = new RestfulApiVersionReader(acceptHeaders, "v");
});
}
}
```
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
---
uid: Codebelt.Extensions.Asp.Versioning.RestfulApiVersioningOptions
example:
- *content
---
Inspect or adjust the defaults applied by `AddRestfulApiVersioning` by constructing a `RestfulApiVersioningOptions` instance directly. Defaults include API version 1.0, the parameter name `"v"`, a broad set of accepted media types, `CurrentImplementationApiVersionSelector`, and custom RFC 7807 problem-details handling. The example below trims the accepted media-type list to JSON only and switches the version selector to always route to the lowest implemented version.
```csharp
using System.Collections.Generic;
using Asp.Versioning;
using Codebelt.Extensions.Asp.Versioning;
namespace Codebelt.Extensions.Asp.Versioning;
public class VersioningOptionsSetup
{
public static RestfulApiVersioningOptions CreateOptions()
{
var options = new RestfulApiVersioningOptions
{
DefaultApiVersion = new ApiVersion(1, 0),
ParameterName = "v",
ReportApiVersions = true,
ValidAcceptHeaders = new List<string>
{
"application/json",
"text/json"
}
};
options.UseApiVersionSelector<LowestImplementedApiVersionSelector>();
return options;
}
}
```
---
uid: Codebelt.Extensions.Asp.Versioning.RestfulApiVersioningOptions
example:
- *content
---
Inspect or adjust the defaults applied by `AddRestfulApiVersioning` by constructing a `RestfulApiVersioningOptions` instance directly. Defaults include API version 1.0, the parameter name `"v"`, a broad set of accepted media types, `CurrentImplementationApiVersionSelector`, and custom RFC 7807 problem-details handling. The example below trims the accepted media-type list to JSON only and switches the version selector to always route to the lowest implemented version.

```csharp
using System.Collections.Generic;
using Asp.Versioning;
using Codebelt.Extensions.Asp.Versioning;

namespace Codebelt.Extensions.Asp.Versioning;

public class VersioningOptionsSetup
{
public static RestfulApiVersioningOptions CreateOptions()
{
var options = new RestfulApiVersioningOptions
{
DefaultApiVersion = new ApiVersion(1, 0),
ParameterName = "v",
ReportApiVersions = true,
ValidAcceptHeaders = new List<string>
{
"application/json",
"text/json"
}
};
options.UseApiVersionSelector<LowestImplementedApiVersionSelector>();
return options;
}
}
```

Loading
Loading