Microsoft.OpenApi.OData 3.0.0

Prefix Reserved
dotnet add package Microsoft.OpenApi.OData --version 3.0.0
                    
NuGet\Install-Package Microsoft.OpenApi.OData -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.OpenApi.OData" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.OpenApi.OData" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.OpenApi.OData" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.OpenApi.OData --version 3.0.0
                    
#r "nuget: Microsoft.OpenApi.OData, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.OpenApi.OData@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.OpenApi.OData&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.OpenApi.OData&version=3.0.0
                    
Install as a Cake Tool

nuget

Convert OData to OpenAPI.NET

Introduction

The Microsoft.OpenAPI.OData.Reader library helps represent an OData service metadata as an OpenApi description. It converts OData CSDL, the XML representation of the Entity Data Model (EDM) describing an OData service into Open API based on OpenAPI.NET object model.

The conversion is based on the mapping doc from OASIS OData OpenAPI v1.0 and uses the following :

  1. Capabilities vocabulary annotation
  2. Authorization vocabulary annotation
  3. Core vocabulary annotation
  4. Navigation property path
  5. Edm operation and operation import path

Overview

The image below is generic overview of how this library can convert the EDM model to an OpenAPI.NET document object.

Convert OData CSDL to OpenAPI

For more information on the CSDL and Entity Data model, please refer to http://www.odata.org/documentation. For more information about the Open API object of model, please refer to http://github.com/microsoft/OpenAPI.NET

Sample code

The following sample code illustrates the use of the library

public static void GenerateOpenApiDescription()
{
    IEdmModel model = GetEdmModel();
    OpenApiDocument document = model.ConvertToOpenApi();
    var outputJSON = document.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
    var outputYAML = document.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
}

public static IEdmModel GetEdmModel()
{
    // load EDM model here...
}

Or with the convert settings:

public static void GenerateOpenApiDescription()
{
    IEdmModel model = GetEdmModel();
    OpenApiConvertSettings settings = new OpenApiConvertSettings
    {
        // configuration
    };
    OpenApiDocument document = model.ConvertToOpenApi(settings);
    var outputJSON = document.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
    var outputYAML = document.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
}

public static IEdmModel GetEdmModel()
{
    // load EDM model here...
}

The GetEdmModel() method can load a model in 3 ways:

  1. Create the Edm model from scratch. For details refer building a basic model

  2. Load the Edm model from CSDL file. The following shows a code sample that loads a model from a csdl file.

    public static IEdmModel GetEdmModel()
    {
        string csdlFilePath = @"c:\csdl.xml";
        string csdl = System.IO.File.ReadAllText(csdlFilePath);
        IEdmModel model = CsdlReader.Parse(XElement.Parse(csdl).CreateReader());
        return model;
    }
    
  3. Create the Edm model using Web API OData model builder. For details refer to the web api model builder article

Nuget packages

The OpenAPI.OData.reader nuget package is at: https://www.nuget.org/packages/Microsoft.OpenApi.OData/


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.

You can also open an issue directly on this repo via this link.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Microsoft.OpenApi.OData:

Package Downloads
DT-ESA.Elevate.SecureConnectors

Generates DTO classes and provides wrappers for resource access.

Swashbuckle.AspNetCore.Community.OData

Provides support for Microsoft.AspNetCore.OData in Swashbuckle

Microsoft.Restier.AspNetCore.Swagger

Package Description

Eternet.OpenApi.Client

Package Description

DT-ESA.SecureConnectors

Generates DTO classes and provides wrappers for resource access.

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on Microsoft.OpenApi.OData:

Repository Stars
OData/AspNetCoreOData
ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
OData/RESTier
A turn-key library for building RESTful services
christianhelle/httpgenerator
Generate .http files from OpenAPI (Swagger) specifications
unchase/Unchase.OpenAPI.Connectedservice
:scroll: Visual Studio extension to generate OpenAPI (Swagger) web service reference.
Version Downloads Last Updated
3.0.0 7,419 11/12/2025
2.0.0 17,434 7/10/2025
2.0.0-preview.18 749 7/2/2025
2.0.0-preview.17 245 7/2/2025
2.0.0-preview.16 200 7/2/2025
2.0.0-preview.15 893 6/3/2025
2.0.0-preview.14 816 5/14/2025
2.0.0-preview.13 839 4/17/2025
2.0.0-preview.12 1,033 4/2/2025
2.0.0-preview.11 241 3/19/2025
2.0.0-preview.10 761 3/18/2025
2.0.0-preview.7 4,019 10/28/2024
2.0.0-preview.6 779 10/17/2024
2.0.0-preview.5 236 10/11/2024
2.0.0-preview.4 164 10/10/2024
2.0.0-preview.3 429 10/3/2024
2.0.0-preview.2 1,311 8/23/2024
2.0.0-preview.1 161 8/16/2024
1.7.5 66,575 3/31/2025
1.7.4 28,396 1/28/2025
1.7.3 11,936 1/22/2025
1.7.2 11,731 1/20/2025
1.7.1 12,429 1/15/2025
1.7.0 15,001 1/2/2025
1.6.9 13,557 12/24/2024
1.6.8 84,314 7/24/2024
1.6.7 18,756 6/26/2024
1.6.6 23,897 6/11/2024
1.6.5 14,257 5/27/2024
1.6.4 14,879 5/21/2024
1.6.3 15,475 4/29/2024
1.6.2 11,846 4/26/2024
1.6.1 20,572 3/28/2024
1.6.0 23,011 3/18/2024
1.6.0-preview.10 537 3/4/2024
1.6.0-preview.9 179 3/1/2024
1.6.0-preview.8 206 2/13/2024
1.6.0-preview.7 343 2/5/2024
1.6.0-preview.6 126 2/2/2024
1.6.0-preview.5 146 2/1/2024
1.6.0-preview.4 240 1/25/2024
1.6.0-preview.3 156 1/23/2024
1.6.0-preview.2 251 1/16/2024
1.6.0-preview.1 129 1/9/2024
1.5.0 51,195 12/8/2023
1.5.0-preview9 2,303 11/13/2023
1.5.0-preview8 503 11/6/2023
1.5.0-preview7 796 10/26/2023
1.5.0-preview6 319 10/24/2023
1.5.0-preview5 783 10/4/2023
1.5.0-preview4 1,143 9/5/2023
1.5.0-preview3 439 9/1/2023
1.5.0-preview2 1,036 6/14/2023
1.5.0-preview1 447 6/2/2023
1.4.0 128,544 5/3/2023
1.4.0-preview7 451 5/2/2023
1.4.0-preview6 458 4/27/2023
1.4.0-preview5 935 4/20/2023
1.4.0-preview4 416 4/18/2023
1.4.0-preview3 550 4/17/2023
1.4.0-preview2 1,011 4/13/2023
1.4.0-preview1 659 4/5/2023
1.3.0 23,680 3/29/2023
1.3.0-preview4 611 3/22/2023
1.3.0-preview3 552 3/21/2023
1.3.0-preview2 1,008 2/28/2023
1.3.0-preview1 506 2/1/2023
1.2.0 42,786 1/20/2023
1.2.0-preview9 2,430 12/15/2022
1.2.0-preview8 1,194 11/17/2022
1.2.0-preview7 590 11/8/2022
1.2.0-preview6 1,081 11/1/2022
1.2.0-preview5 645 10/24/2022
1.2.0-preview4 874 10/6/2022
1.2.0-preview3 487 10/3/2022
1.2.0-preview2 515 9/28/2022
1.2.0-preview1 475 9/28/2022
1.1.0 73,132 9/14/2022
1.0.11 50,233 7/18/2022
1.0.11-preview5 799 7/8/2022
1.0.11-preview4 700 7/6/2022
1.0.11-preview3 1,312 6/22/2022
1.0.11-preview2 940 6/6/2022
1.0.11-preview1 533 5/30/2022
1.0.10 36,727 5/10/2022
1.0.10-preview3 1,932 3/29/2022
1.0.10-preview2 1,299 3/3/2022
1.0.10-preview1 746 2/25/2022
1.0.9 89,024 10/7/2021
1.0.8 124,138 5/6/2021
1.0.7 32,643 4/13/2021
1.0.6 38,749 2/11/2021
1.0.5 11,949 2/6/2021
1.0.4 72,531 7/21/2020
1.0.2 18,824 5/25/2020
1.0.1 55,439 10/10/2019
1.0.0 13,337 9/25/2019
1.0.0-beta9 18,381 8/13/2019
1.0.0-beta8 3,119 8/6/2019
1.0.0-beta7 5,912 9/24/2018
1.0.0-beta6 1,361 9/19/2018
1.0.0-beta5 1,312 9/7/2018
1.0.0-beta4 2,075 5/30/2018