CSharpEssentials.AspNetCore.OpenApi
6.1.0
See the version list below for details.
dotnet add package CSharpEssentials.AspNetCore.OpenApi --version 6.1.0
NuGet\Install-Package CSharpEssentials.AspNetCore.OpenApi -Version 6.1.0
<PackageReference Include="CSharpEssentials.AspNetCore.OpenApi" Version="6.1.0" />
<PackageVersion Include="CSharpEssentials.AspNetCore.OpenApi" Version="6.1.0" />
<PackageReference Include="CSharpEssentials.AspNetCore.OpenApi" />
paket add CSharpEssentials.AspNetCore.OpenApi --version 6.1.0
#r "nuget: CSharpEssentials.AspNetCore.OpenApi, 6.1.0"
#:package CSharpEssentials.AspNetCore.OpenApi@6.1.0
#addin nuget:?package=CSharpEssentials.AspNetCore.OpenApi&version=6.1.0
#tool nuget:?package=CSharpEssentials.AspNetCore.OpenApi&version=6.1.0
CSharpEssentials.AspNetCore.OpenApi
Microsoft.AspNetCore.OpenApi integration for the CSharpEssentials enum conventions.
One host, one OpenAPI package: reference either
CSharpEssentials.AspNetCore.OpenApi(Microsoft.AspNetCore.OpenApi) orCSharpEssentials.AspNetCore.Swashbuckle(Swashbuckle), never both. Both useMicrosoft.OpenApi2.x.
Installation
dotnet add package CSharpEssentials.AspNetCore.OpenApi
Targets net10.0 with Microsoft.AspNetCore.OpenApi 10.x and Microsoft.OpenApi 2.x. A net11.0 target with Microsoft.AspNetCore.OpenApi 11.x needs Microsoft.OpenApi 3.x and will come later as a non-breaking addition.
Enum schemas
builder.Services.AddEnumConventions();
builder.Services.AddOpenApi("v1", o => o.AddEnumConventions());
builder.Services.AddOpenApi("v2", o => o.AddEnumConventions());
app.MapOpenApi();
AddEnumConventions adds a schema, an operation and a document transformer. Enums handled by the enum conventions ([StringEnum] or generated metadata) are described the way they are written:
"OrderStatus": {
"type": "string",
"description": "Order lifecycle state.\n\n| value | number | description |\n|---|---|---|\n| `pending` | 0 | Created, waiting for payment. |\n| `unknown` | 99 | Response only: a value this API version does not know. |",
"enum": [ "pending", "unknown" ],
"x-enum-varnames": [ "Pending", "Unknown" ],
"x-enum-descriptions": [ "Created, waiting for payment.", "Response only: a value this API version does not know." ],
"x-enum-numeric-values": [ 0, 99 ]
}
- One component per enum. Your description (XML
<summary>or[Description]) is kept and the value table is appended. Obsolete members are marked(deprecated), the[EnumFallback]memberResponse only:. Aliases are accepted but not listed. defaultis the wire name ([DefaultValue]on a property, a default parameter value).[Flags]enums are arrays withuniqueItems: true; collections are arrays of the component.- Nullable is written where the enum is used, by the document's OpenAPI version:
allOf+nullable: truefor 3.0,oneOfwith{ "type": "null" }for 3.1. - A document whose operations all write numbers (
WithEnumWireFormat(EnumWireFormat.Number)on the group,[EnumWireFormat]on the controller) describes the enums asinteger(int32/int64by underlying type). A document that mixes formats describes strings and marks each number operation withx-enum-wire-format: numberand a description note; it also logs one warning per enum used in both formats (once per document). One document per API version never mixes. - Operations with a header selected format (
WithEnumWireFormat("X-Enum-Format", ...)) show the format of a request without the header, plusx-enum-wire-format-headerand a note. A selector that throws for such a request is described with the globalWriteAsformat and logged once as a warning. - Enums without
[StringEnum]or metadata keep the framework schema; nothing throws.
The Swashbuckle package produces the same enum schemas (both are compared with the same golden files).
Scalar
No helper is needed; list the documents:
app.MapOpenApi();
app.MapScalarApiReference(o => o.AddDocument("v1").AddDocument("v2"));
Hosts without the Web SDK
Microsoft.AspNetCore.OpenApi intercepts AddOpenApi with generated code. A project on Microsoft.NET.Sdk (instead of Microsoft.NET.Sdk.Web) enables it:
<InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.AspNetCore.OpenApi.Generated</InterceptorsNamespaces>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Asp.Versioning.Abstractions (>= 8.1.0)
- Asp.Versioning.Http (>= 8.1.0)
- Asp.Versioning.Mvc (>= 8.1.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- CSharpEssentials.AspNetCore (>= 6.1.0)
- Microsoft.AspNetCore.OpenApi (>= 10.0.0 && < 11.0.0)
- Microsoft.OpenApi (>= 2.7.5 && < 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.