From 0879ed37c671179db3dc79669dd7d4378cd55feb Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Fri, 28 Jun 2019 11:46:00 -0700 Subject: [PATCH] more code cleanup --- .../Generator/OpenApiParameterGenerator.cs | 4 +- .../VocabularyAnnotationsExtensions.cs | 89 ------------------- 2 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 src/Microsoft.OpenApi.OData.Reader/Vocabulary/VocabularyAnnotationsExtensions.cs diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs index 780fc58..2a44492 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs @@ -179,7 +179,7 @@ namespace Microsoft.OpenApi.OData.Generator Utils.CheckArgumentNull(context, nameof(context)); Utils.CheckArgumentNull(target, nameof(target)); - bool? top = context.Model.GetTopSupported(target); + bool? top = context.Model.GetBoolean(target, CapabilitiesConstants.TopSupported); if (top == null || top.Value) { return new OpenApiParameter @@ -202,7 +202,7 @@ namespace Microsoft.OpenApi.OData.Generator Utils.CheckArgumentNull(context, nameof(context)); Utils.CheckArgumentNull(target, nameof(target)); - bool? skip = context.Model.GetSkipSupported(target); + bool? skip = context.Model.GetBoolean(target, CapabilitiesConstants.SkipSupported); if (skip == null || skip.Value) { return new OpenApiParameter diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/VocabularyAnnotationsExtensions.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/VocabularyAnnotationsExtensions.cs deleted file mode 100644 index e16b9d6..0000000 --- a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/VocabularyAnnotationsExtensions.cs +++ /dev/null @@ -1,89 +0,0 @@ -// ------------------------------------------------------------ -// 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; -using Microsoft.OData.Edm.Vocabularies; -using Microsoft.OpenApi.OData.Edm; -using Microsoft.OpenApi.OData.Vocabulary.Capabilities; - -namespace Microsoft.OpenApi.OData.Vocabulary -{ - /// - /// Constant values for Vocabulary - /// - internal static class VocabularyAnnotationsExtensions - { - /// - /// Gets Org.OData.Capabilities.V1.SearchRestrictions. - /// - /// The Edm model. - /// The target. - /// The Org.OData.Capabilities.V1.SearchRestrictions or null. - public static T GetRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName) - where T : IRecord, new() - { - return model.GetRestrictionsImpl(target, qualifiedName); - } - - /// - /// Gets Org.OData.Capabilities.V1.TopSupported. - /// - /// The Edm model. - /// The target. - /// The Org.OData.Capabilities.V1.TopSupported or null. - public static bool? GetTopSupported(this IEdmModel model, IEdmVocabularyAnnotatable target) - { - return GetSupported(model, target, CapabilitiesConstants.TopSupported); - } - - /// - /// Gets Org.OData.Capabilities.V1.SkipSupported. - /// - /// The Edm model. - /// The target. - /// The Org.OData.Capabilities.V1.SkipSupported or null. - public static bool? GetSkipSupported(this IEdmModel model, IEdmVocabularyAnnotatable target) - { - return GetSupported(model, target, CapabilitiesConstants.SkipSupported); - } - - private static bool? GetSupported(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName) - { - bool? supported = model.GetBoolean(target, qualifiedName); - if (supported == null) - { - IEdmNavigationSource navigationSource = target as IEdmNavigationSource; - - // if not, search the entity type. - if (navigationSource != null) - { - IEdmEntityType entityType = navigationSource.EntityType(); - supported = model.GetBoolean(entityType, qualifiedName); - } - } - - return supported; - } - - private static T GetRestrictionsImpl(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName) - where T : IRecord, new() - { - T restrictions = model.GetRecord(target, qualifiedName); - if (restrictions == null) - { - IEdmNavigationSource navigationSource = target as IEdmNavigationSource; - - // if not, search the entity type. - if (navigationSource != null) - { - IEdmEntityType entityType = navigationSource.EntityType(); - restrictions = model.GetRecord(entityType, qualifiedName); - } - } - - return restrictions; - } - } -}