Generates OpenAPI document from OData CSDL
Перейти к файлу
Andrew Omondi 5f454303bf Revert to false default 2023-02-28 13:31:33 +03:00
.azure-pipelines - switches to net2 for ESRP 2022-11-10 09:52:31 -05:00
.github - replaces auto-build 2023-01-16 11:04:00 -05:00
.vscode - upgrades to dotnet 7 2022-11-08 10:19:00 -05:00
docs support put operations on complex properties 2022-02-08 13:27:43 +03:00
scripts - adds missing force flag for unattended install 2022-03-03 12:46:03 -05:00
src Revert to false default 2023-02-28 13:31:33 +03:00
test/Microsoft.OpenAPI.OData.Reader.Tests Alias typesegment paths 2023-02-28 12:24:26 +03:00
tool Bump Microsoft.OpenApi from 1.6.1 to 1.6.2 2023-02-21 19:35:58 +00:00
.editorconfig Fix paths when operation is bound to a type derived from the type of a 2021-02-10 16:07:31 -08:00
.gitignore Initial commit 2017-10-19 09:39:14 -07:00
Build.props Enable auto-generate the Version from Custom build task 2019-10-03 16:35:05 -07:00
LICENSE Initial commit 2017-10-19 09:39:17 -07:00
Microsoft.OpenApi.OData.sln - fixes casing for projects reference 2022-11-29 10:21:37 -05:00
README.md - replaces ADO by nuget badge since project is not public 2022-02-28 11:16:15 -05:00
SECURITY.md Microsoft mandatory file (#224) 2022-05-30 08:59:23 +03:00
build.cmd modify the output, add the build script and skip strong name 2017-12-20 16:15:17 -08:00
build.ps1 Modify the skip strong name script 2020-01-24 12:53:26 -08:00
build.root Update to ODL 7.6.1 and add some build scripts 2019-10-03 09:51:35 -07:00

README.md

nuget

Convert OData to OpenAPI.NET [Preview]

[Disclaimer:This library is in a preview state. Feedback and contribution is welcome!]

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

Nightly builds

The nightly build process will upload a Nuget package for OpenAPI.OData.reader to OpenAPIOData MyGet gallery.

To connect to OpenAPI.OData.reader feed, use this URL source.

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.

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.