diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmAnnotationExtensions.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmAnnotationExtensions.cs index b5eb1e32..9b9658f9 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmAnnotationExtensions.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmAnnotationExtensions.cs @@ -9,9 +9,11 @@ using System.Linq; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Vocabularies; +using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Vocabulary; using Microsoft.OpenApi.OData.Vocabulary.Authorization; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Edm { @@ -256,6 +258,21 @@ public static IEnumerable GetCollection(this IEdmModel model, IEdmVocabula }); } + /// + /// Gets the links record value (a complex type) for the given . + /// + /// The Edm model. + /// The Edm target. + /// The link relation type for path operation. + /// Null or the links record value (a complex type) for this annotation. + public static Link GetLinkRecord(this IEdmModel model, IEdmVocabularyAnnotatable target, string linkRel) + { + Utils.CheckArgumentNull(model, nameof(model)); + Utils.CheckArgumentNull(target, nameof(target)); + + return model.GetCollection(target, CoreConstants.Links)?.FirstOrDefault(x => x.Rel == linkRel); + } + /// /// Create the corresponding Authorization object. /// diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs index edf433ce..63841a68 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs @@ -177,7 +177,7 @@ internal IEnumerable GetDeprecationInformations(IEdmVoc { return annotable == null ? Enumerable.Empty() : - (Model?.GetCollection(annotable, "Org.OData.Core.V1.Revisions") ?? + (Model?.GetCollection(annotable, CoreConstants.Revisions) ?? Enumerable.Empty()); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs index 5b7ed51e..00ea04b2 100644 --- a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs +++ b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs @@ -8,6 +8,7 @@ using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Extensions; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData { @@ -179,6 +180,11 @@ public string PathPrefix /// public bool ShowMsDosGroupPath { get; set; } = true; + /// + /// Gets/sets links to external documentation for operations + /// + public bool ShowExternalDocs { get; set; } = true; + /// /// Gets/sets a the path provider. /// @@ -259,6 +265,20 @@ public string PathPrefix /// public bool UseSuccessStatusCodeRange { get; set; } = false; + /// + /// Get/Sets a dictionary containing a mapping of HTTP methods to custom link relation types + /// + public Dictionary CustomHttpMethodLinkRelMapping { get; set; } = new() + { + { LinkRelKey.List, "https://graph.microsoft.com/rels/docs/list" }, + { LinkRelKey.ReadByKey, "https://graph.microsoft.com/rels/docs/get" }, + { LinkRelKey.Create, "https://graph.microsoft.com/rels/docs/create" }, + { LinkRelKey.Update, "https://graph.microsoft.com/rels/docs/update" }, + { LinkRelKey.Delete, "https://graph.microsoft.com/rels/docs/delete" }, + { LinkRelKey.Action, "https://graph.microsoft.com/rels/docs/action" }, + { LinkRelKey.Function, "https://graph.microsoft.com/rels/docs/function" } + }; + internal OpenApiConvertSettings Clone() { var newSettings = new OpenApiConvertSettings @@ -288,6 +308,7 @@ internal OpenApiConvertSettings Clone() RequireDerivedTypesConstraintForBoundOperations = this.RequireDerivedTypesConstraintForBoundOperations, ShowSchemaExamples = this.ShowSchemaExamples, ShowRootPath = this.ShowRootPath, + ShowExternalDocs = this.ShowExternalDocs, PathProvider = this.PathProvider, EnableDollarCountPath = this.EnableDollarCountPath, AddSingleQuotesForStringParameters = this.AddSingleQuotesForStringParameters, @@ -300,6 +321,7 @@ internal OpenApiConvertSettings Clone() RequireRestrictionAnnotationsToGenerateComplexPropertyPaths = this.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths, ExpandDerivedTypesNavigationProperties = this.ExpandDerivedTypesNavigationProperties, CustomXMLAttributesMapping = this.CustomXMLAttributesMapping, + CustomHttpMethodLinkRelMapping = this.CustomHttpMethodLinkRelMapping, AppendBoundOperationsOnDerivedTypeCastSegments = this.AppendBoundOperationsOnDerivedTypeCastSegments, UseSuccessStatusCodeRange = this.UseSuccessStatusCodeRange }; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs index 77cd097a..1844181b 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs @@ -7,7 +7,9 @@ using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; +using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Generator; +using Microsoft.OpenApi.OData.Vocabulary.Capabilities; namespace Microsoft.OpenApi.OData.Operation { @@ -19,6 +21,19 @@ internal class EdmActionOperationHandler : EdmOperationOperationHandler /// public override OperationType OperationType => OperationType.Post; + /// + protected override void SetBasicInfo(OpenApiOperation operation) + { + base.SetBasicInfo(operation); + + // Description + var insertRestrictions = Context.Model.GetRecord(EdmOperation, CapabilitiesConstants.InsertRestrictions); + if (!string.IsNullOrWhiteSpace(insertRestrictions?.LongDescription)) + { + operation.Description = insertRestrictions.LongDescription; + } + } + /// protected override void SetRequestBody(OpenApiOperation operation) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs index c1134f8d..192a2976 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs @@ -7,6 +7,8 @@ using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; +using Microsoft.OpenApi.OData.Edm; +using Microsoft.OpenApi.OData.Vocabulary.Capabilities; namespace Microsoft.OpenApi.OData.Operation { @@ -23,6 +25,19 @@ internal class EdmFunctionOperationHandler : EdmOperationOperationHandler /// public IEdmFunction Function => EdmOperation as IEdmFunction; + /// + protected override void SetBasicInfo(OpenApiOperation operation) + { + base.SetBasicInfo(operation); + + // Description + var readRestrictions = Context.Model.GetRecord(EdmOperation, CapabilitiesConstants.ReadRestrictions); + if (!string.IsNullOrWhiteSpace(readRestrictions?.LongDescription)) + { + operation.Description = readRestrictions.LongDescription; + } + } + /// protected override void SetExtensions(OpenApiOperation operation) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs index 36c3b141..13ee7af7 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs @@ -13,6 +13,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -152,5 +153,18 @@ internal static string PathAsString(IEnumerable path) { return String.Join("/", path); } + + /// + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(EdmOperationImport, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs index b8bded2f..cb50b01c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs @@ -12,6 +12,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -42,9 +43,7 @@ internal abstract class EdmOperationOperationHandler : OperationHandler /// protected override void Initialize(ODataContext context, ODataPath path) - { - base.Initialize(context, path); - + { // It's bound operation, the first segment must be the navigaiton source. ODataNavigationSourceSegment navigationSourceSegment = path.FirstSegment as ODataNavigationSourceSegment; NavigationSource = navigationSourceSegment.NavigationSource; @@ -53,6 +52,8 @@ protected override void Initialize(ODataContext context, ODataPath path) EdmOperation = OperationSegment.Operation; HasTypeCast = path.Segments.Any(s => s is ODataTypeCastSegment); + + base.Initialize(context, path); } /// @@ -198,5 +199,30 @@ protected override void AppendCustomParameters(OpenApiOperation operation) AppendCustomParameters(operation, restriction.CustomQueryOptions, ParameterLocation.Query); } } + + /// + protected override void SetCustomLinkRelType() + { + if (Context.Settings.CustomHttpMethodLinkRelMapping != null && EdmOperation != null) + { + LinkRelKey key = EdmOperation.IsAction() ? LinkRelKey.Action : LinkRelKey.Function; + Context.Settings.CustomHttpMethodLinkRelMapping.TryGetValue(key, out string linkRelValue); + CustomLinkRel = linkRelValue; + } + } + + + /// + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(EdmOperation, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs index 750d11b7..bffd943a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs @@ -8,6 +8,7 @@ using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -56,5 +57,18 @@ protected override void SetExtensions(OpenApiOperation operation) base.SetExtensions(operation); } + + /// + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(EntitySet, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs index a14c75de..85e150ae 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using Microsoft.OpenApi.OData.Vocabulary.Core; using System.Collections.Generic; using System.Linq; @@ -24,7 +25,7 @@ internal abstract class MediaEntityOperationalHandler : NavigationPropertyOperat /// Gets/Sets the NavigationSource segment /// protected ODataNavigationSourceSegment NavigationSourceSegment { get; private set; } - + /// /// Gets/Sets flag indicating whether path is navigation property path /// @@ -204,5 +205,18 @@ private IEdmNavigationProperty GetNavigationProperty(IEdmEntityType entityType, { return entityType.DeclaredNavigationProperties().FirstOrDefault(x => x.Name.Equals(identifier)); } + + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && IsNavigationPropertyPath && + Context.Model.GetLinkRecord(NavigationProperty, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs index ff1079a8..59d26222 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs @@ -12,6 +12,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -156,6 +157,19 @@ protected string GetOperationId(string prefix = null) return string.Join(".", items); } + /// + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(NavigationProperty, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } + /// /// Retrieves the CRUD restrictions annotations for the navigation property /// in context, given a capability annotation term. diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs index 510314fe..7d47d8f8 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System; using System.Collections.Generic; using System.Linq; using Microsoft.OpenApi.Any; @@ -11,6 +12,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -47,6 +49,9 @@ public virtual OpenApiOperation CreateOperation(ODataContext context, ODataPath SetBasicInfo(operation); SetDeprecation(operation); + // ExternalDocs + SetExternalDocs(operation); + // Security SetSecurity(operation); @@ -68,12 +73,13 @@ will be used in the Responses when creating Links. // Extensions SetExtensions(operation); + return operation; } private void SetDeprecation(OpenApiOperation operation) { - if(operation != null && Context.Settings.EnableDeprecationInformation) + if (operation != null && Context.Settings.EnableDeprecationInformation) { var deprecationInfo = Path.SelectMany(x => x.GetAnnotables()) .SelectMany(x => Context.GetDeprecationInformations(x)) @@ -82,7 +88,7 @@ private void SetDeprecation(OpenApiOperation operation) .ThenByDescending(x => x.RemovalDate) .FirstOrDefault(); - if(deprecationInfo != null) + if (deprecationInfo != null) { operation.Deprecated = true; var deprecationDetails = deprecationInfo.GetOpenApiExtension(); @@ -101,6 +107,11 @@ private void SetDeprecation(OpenApiOperation operation) /// protected ODataPath Path { get; private set; } + /// + /// Gets the custom link relation type for path based on operation type + /// + protected string CustomLinkRel { get; set; } + /// /// Initialize the handler. /// It should be call ahead of in derived class. @@ -108,7 +119,9 @@ private void SetDeprecation(OpenApiOperation operation) /// The context. /// The path. protected virtual void Initialize(ODataContext context, ODataPath path) - { } + { + SetCustomLinkRelType(); + } /// /// Set the basic information for . @@ -177,21 +190,26 @@ protected virtual void SetTags(OpenApiOperation operation) protected virtual void SetExtensions(OpenApiOperation operation) { } + /// + /// Set the ExternalDocs information for . + /// + /// The . + protected virtual void SetExternalDocs(OpenApiOperation operation) + { } + /// /// Set the customized parameters for the operation. /// /// The operation. protected virtual void AppendCustomParameters(OpenApiOperation operation) - { - } + { } /// /// Set the addition annotation for the response. /// /// The operation. protected virtual void AppendHttpResponses(OpenApiOperation operation) - { - } + { } /// /// Sets the custom parameters. @@ -246,5 +264,29 @@ protected static void AppendCustomParameters(OpenApiOperation operation, IList + /// Set link relation type to be used to get external docs link for path operation + /// + protected virtual void SetCustomLinkRelType() + { + if (Context.Settings.CustomHttpMethodLinkRelMapping != null) + { + LinkRelKey? key = OperationType switch + { + OperationType.Get => Path.LastSegment?.Kind == ODataSegmentKind.Key ? LinkRelKey.ReadByKey : LinkRelKey.List, + OperationType.Post => LinkRelKey.Create, + OperationType.Patch => LinkRelKey.Update, + OperationType.Delete => LinkRelKey.Delete, + _ => null, + }; + + if (key != null) + { + Context.Settings.CustomHttpMethodLinkRelMapping.TryGetValue((LinkRelKey)key, out string linkRelValue); + CustomLinkRel = linkRelValue; + } + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs index ff1b049a..393f77bc 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs @@ -8,6 +8,7 @@ using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; +using Microsoft.OpenApi.OData.Vocabulary.Core; namespace Microsoft.OpenApi.OData.Operation { @@ -60,5 +61,18 @@ protected override void SetExtensions(OpenApiOperation operation) base.SetExtensions(operation); } + + /// + protected override void SetExternalDocs(OpenApiOperation operation) + { + if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(Singleton, CustomLinkRel) is Link externalDocs) + { + operation.ExternalDocs = new OpenApiExternalDocs() + { + Description = CoreConstants.ExternalDocsDescription, + Url = externalDocs.Href + }; + } + } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt index 9ec0d341..56210bd2 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt +++ b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt @@ -7,14 +7,26 @@ Microsoft.OpenApi.OData.Edm.EdmModelExtensions Microsoft.OpenApi.OData.Edm.EdmTypeExtensions Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.set -> void +Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.get -> System.Collections.Generic.Dictionary +Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.ExpandDerivedTypesNavigationProperties.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.ExpandDerivedTypesNavigationProperties.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomXMLAttributesMapping.get -> System.Collections.Generic.Dictionary Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomXMLAttributesMapping.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths.set -> void +Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.get -> bool +Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.set -> void +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Action = 6 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Create = 2 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Delete = 4 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Function = 5 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.List = 1 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.ReadByKey = 0 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Update = 3 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey static Microsoft.OpenApi.OData.Common.OpenApiOperationExtensions.AddErrorResponses(this Microsoft.OpenApi.Models.OpenApiOperation operation, Microsoft.OpenApi.OData.OpenApiConvertSettings settings, bool addNoContent = false, Microsoft.OpenApi.Models.OpenApiSchema schema = null) -> void static Microsoft.OpenApi.OData.Edm.EdmTypeExtensions.ShouldPathParameterBeQuoted(this Microsoft.OData.Edm.IEdmType edmType, Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> bool Microsoft.OpenApi.OData.Edm.IODataPathProvider diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/CoreConstants.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/CoreConstants.cs new file mode 100644 index 00000000..3847db4f --- /dev/null +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/CoreConstants.cs @@ -0,0 +1,28 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ----------------------------------------------------------- + +namespace Microsoft.OpenApi.OData.Vocabulary.Core +{ + /// + /// Constants for the Core vocabulary + /// + internal static class CoreConstants + { + /// + /// Org.OData.Core.V1.Links + /// + public const string Links = "Org.OData.Core.V1.Links"; + + /// + /// Org.OData.Core.V1.Revisions + /// + public const string Revisions = "Org.OData.Core.V1.Revisions"; + + /// + /// External docs description. + /// + public const string ExternalDocsDescription = "Find more info here"; + } +} diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/Link.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/Link.cs new file mode 100644 index 00000000..211de695 --- /dev/null +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/Link.cs @@ -0,0 +1,40 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------ + +using Microsoft.OData.Edm.Vocabularies; +using Microsoft.OpenApi.OData.Common; +using Microsoft.OpenApi.OData.Edm; +using System; + +namespace Microsoft.OpenApi.OData.Vocabulary.Core +{ + /// + /// Complex Type: Org.OData.Core.V1.Link + /// + [Term("Org.OData.Core.V1.Links")] + internal class Link : IRecord + { + /// + /// The link relation type. + /// + public string Rel { get; private set; } + + /// + /// The link to the documentation. + /// + public Uri Href { get; private set; } + + /// + /// Init the . + /// + /// + public virtual void Initialize(IEdmRecordExpression record) + { + Utils.CheckArgumentNull(record, nameof(record)); + Rel = record.GetString("rel"); + Href = new Uri(record.GetString("href")); + } + } +} diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/LinkRelKey.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/LinkRelKey.cs new file mode 100644 index 00000000..833a46b6 --- /dev/null +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/LinkRelKey.cs @@ -0,0 +1,44 @@ +namespace Microsoft.OpenApi.OData.Vocabulary.Core +{ + + /// + /// Custom link relation type keys + /// + public enum LinkRelKey + { + /// + /// Identifies external documentation for a GET operation on an entity. + /// + ReadByKey, + + /// + /// Identifies external documentation for a GET operation on an entity set. + /// + List, + + /// + /// Identifies external documentation for a POST operation. + /// + Create, + + /// + /// Identifies external documentation for a PATCH operation. + /// + Update, + + /// + /// Identifies external documentation for a DELETE operation. + /// + Delete, + + /// + /// Identifies external documentation for a function. + /// + Function, + + /// + /// Identifies external documentation for an action. + /// + Action + } +}