- Notifications
You must be signed in to change notification settings - Fork65
Generates OpenAPI document from OData CSDL
License
microsoft/OpenAPI.NET.OData
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TheMicrosoft.OpenAPI.OData.Reader library helps represent an OData service metadata as an OpenApi description. It convertsODataCSDL, the XML representation of the Entity Data Model (EDM) describing an OData service intoOpen API based onOpenAPI.NET object model.
The conversion is based on the mapping doc fromOASIS OData OpenAPI v1.0 and uses the following :
- Capabilities vocabulary annotation
- Authorization vocabulary annotation
- Core vocabulary annotation
- Navigation property path
- Edm operation and operation import path
The image below is generic overview of how this library can convert the EDM model to anOpenAPI.NET document object.
For more information on the CSDL and Entity Data model, please refer tohttp://www.odata.org/documentation.For more information about the Open API object of model, please refer tohttp://github.com/microsoft/OpenAPI.NET
The following sample code illustrates the use of the library
publicstaticvoidGenerateOpenApiDescription(){IEdmModelmodel=GetEdmModel();OpenApiDocumentdocument=model.ConvertToOpenApi();varoutputJSON=document.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);varoutputYAML=document.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);}publicstaticIEdmModelGetEdmModel(){// load EDM model here...}
Or with the convert settings:
publicstaticvoidGenerateOpenApiDescription(){IEdmModelmodel=GetEdmModel();OpenApiConvertSettingssettings=newOpenApiConvertSettings{// configuration};OpenApiDocumentdocument=model.ConvertToOpenApi(settings);varoutputJSON=document.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);varoutputYAML=document.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);}publicstaticIEdmModelGetEdmModel(){// load EDM model here...}
TheGetEdmModel() method can load a model in 3 ways:
Create the Edm model from scratch. For details referbuilding a basic model
Load the Edm model from CSDL file. The following shows a code sample that loads a model from a csdl file.
publicstaticIEdmModelGetEdmModel(){stringcsdlFilePath=@"c:\csdl.xml";stringcsdl=System.IO.File.ReadAllText(csdlFilePath);IEdmModelmodel=CsdlReader.Parse(XElement.Parse(csdl).CreateReader());returnmodel;}
Create the Edm model using Web API OData model builder. For details refer to theweb api model builder article
The OpenAPI.OData.reader nuget package is at:https://www.nuget.org/packages/Microsoft.OpenApi.OData/
This project welcomes contributions and suggestions. Most contributions require you to agree to aContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant usthe rights to use your contribution. For details, visithttps://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to providea CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructionsprovided 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 thislink.
This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQ orcontactopencode@microsoft.com with any additional questions or comments.
About
Generates OpenAPI document from OData CSDL
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
