OpenAPI.NET is the Microsoft-maintained .NET SDK that provides a shared object model for OpenAPI descriptions, together with readers and writers that convert OpenAPI JSON and YAML documents into and out of that model, and it is aimed at C# and .NET developers who build, validate, or transform OpenAPI documents in code.
What it is
OpenAPI.NET is a .NET library published as NuGet packages under the MIT licence, written in C#, and hosted in the microsoft organization on GitHub. Its stated objectives are to provide a single shared object model in .NET for OpenAPI descriptions, to include the most primitive reader for ingesting OpenAPI JSON and YAML documents in both V2 and V3 formats, to provide writers for both V2 and V3 specification formats, and to enable developers to create readers that translate other data formats into OpenAPI descriptions. The repository carries 1610 stars, 286 forks, and 31 open issues, and the project sits in the Developer Tools / API Development & Testing category.
The problem it solves is per-project reimplementation of OpenAPI parsing and serialization. Without a shared model, every .NET tool that needs to read or emit an OpenAPI document has to hand-roll its own handling of raw OpenAPI JSON and YAML text, which duplicates effort and drifts from the specification. OpenAPI.NET replaces that with concrete types such as OpenApiDocument, OpenApiInfo, OpenApiPaths, OpenApiPathItem, OpenApiOperation, and OpenApiResponses, plus serializers that read and write the underlying JSON and YAML. It is the base object model for the OpenAPI.NET family of processor projects rather than a single closed tool.
Key capabilities
- Models and writers ship in the
Microsoft.OpenApi NuGet package, covering OpenAPI V2 and V3 object representation and serialization.
- YAML ingestion is available separately through the
Microsoft.OpenApi.YamlReader NuGet package, while the base JSON and YAML processors are built into the project.
- A new major version adds support for OpenAPI 3.2, with changes documented in the upgrade guide at
./docs/upgrade-guide-3.md.
- Documents load directly from a URL and serialize to a chosen specification version, for example
await OpenApiDocument.LoadAsync(...) followed by await openApiDocument.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0) to emit V2 JSON.
Microsoft.OpenApi.Hidi is a command line tool, shipped as a NuGet package, for validating and transforming OpenAPI descriptions.
- The C# Comment / Annotation Processor (
OpenAPI.NET.CSharpAnnotations) converts standard .NET /// comments emitted from a build into an OpenAPI.NET document object.
- The OData CSDL Processor (
OpenAPI.NET.OData) converts the XML representation of the Entity Data Model describing an OData service into an OpenAPI.NET document object.
Who uses it and how
- .NET API teams that annotate controllers with
/// comments and let MSBuild output feed the C# Comment / Annotation Processor, producing an OpenAPI.NET document at build time instead of maintaining specification files by hand.
- OData service owners who need an OpenAPI description derived from the XML Entity Data Model already describing their service, via the OData CSDL Processor.
- Pipeline and CI authors who validate or transform descriptions with the
Microsoft.OpenApi.Hidi command line tool rather than writing custom validation code.
- Library and tooling authors who consume the shared OpenAPI.NET object model so that readers and writers interoperate across projects instead of splitting into incompatible private parsers.
- Teams that ingest a V3 description from a URL and emit V2 JSON for a downstream consumer that still requires the older format.
Getting started
Install the core Microsoft.OpenApi NuGet package, and add Microsoft.OpenApi.YamlReader when YAML ingestion is needed. For validation and transformation from the command line, install Microsoft.OpenApi.Hidi, whose installation guidelines and documentation live alongside the source in src/Microsoft.OpenApi.Hidi/readme.md.
How it compares
No list of paid products replaced by this project appears in the available facts, and no directly comparable tool is named either, so OpenAPI.NET stands alone in this registry. The honest framing is that it is the base object model for its own processor ecosystem, including the C# Comment / Annotation and OData CSDL processors, rather than a substitute for a named commercial product. Any comparison against other OpenAPI tooling would have to come from outside these facts.
When to use it — and when not to
Choose OpenAPI.NET when the codebase and toolchain are already .NET and the work involves reading, writing, validating, or transforming OpenAPI descriptions in process or in CI. Avoid it for non-.NET stacks, where the C# object model cannot be consumed without adding a .NET runtime to the pipeline. A self-hoster operates no database, object storage, or SMTP, because this is a library and a CLI rather than a service, but adopters must budget for major-version migrations such as the 3.x upgrade documented in ./docs/upgrade-guide-3.md, and they should note the 31 open issues and that contribution requires agreeing to a Contributor License Agreement.
project readme (upstream, from github) — read inline

OpenAPI.NET
The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
See more information on the OpenAPI specification and its history here: OpenAPI Initiative
Project Objectives:
- Provide a single shared object model in .NET for OpenAPI descriptions.
- Include the most primitive Reader for ingesting OpenAPI JSON and YAML documents in both V2 and V3 formats.
- Provide OpenAPI description writers for both V2 and V3 specification formats.
- Enable developers to create Readers that translate different data formats into OpenAPI descriptions.
Installation
Note: we just released a new major version of the library, which brings support for OpenAPI 3.2!
You can read more about the changes of this upcoming version in the upgrade guide.
Processors
The OpenAPI.NET project holds the base object model for representing OpenAPI documents as .NET objects. Some developers have found the need to write processors that convert other data formats into this OpenAPI.NET object model. We'd like to curate that list of processors in this section of the readme.
The base JSON and YAML processors are built into this project. Below is the list of the other supported processor projects.
C# Comment / Annotation Processor : Converts standard .NET annotations ( /// comments ) emitted from your build (MSBuild.exe) into OpenAPI.NET document object.
OData CSDL Processor : Converts the XML representation of the Entity Data Model (EDM) describing an OData Service into OpenAPI.NET document object.
Example Usage
Creating an OpenAPI Document
var document = new OpenApiDocument
{
Info = new OpenApiInfo
{
Version = "1.0.0",
Title = "Swagger Petstore (Simple)",
},
Servers = new List<OpenApiServer>
{
new OpenApiServer { Url = "http://petstore.swagger.io/api" }
},
Paths = new OpenApiPaths
{
["/pets"] = new OpenApiPathItem
{
Operations = new()
{
[HttpMethod.Get] = new OpenApiOperation
{
Description = "Returns all pets from the system that the user has access to",
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse
{
Description = "OK"
}
}
}
}
}
}
};
Reading and writing an OpenAPI description
var (openApiDocument, _) = await OpenApiDocument.LoadAsync("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore.yaml");
// Write V2 as JSON
var outputString = await openApiDocument.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0);
Validating/Testing OpenAPI descriptions
In order to test the validity of an OpenApi document, we avail the following tools:
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact [email protected] with any additional questions or comments.
To provide feedback and ask questions you can use Stack Overflow with the OpenAPI.NET tag.