more code cleanup

This commit is contained in:
Sam Xu 2019-06-28 11:46:00 -07:00
parent 5a1efcc08e
commit 0879ed37c6
2 changed files with 2 additions and 91 deletions

View file

@ -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

View file

@ -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
{
/// <summary>
/// Constant values for Vocabulary
/// </summary>
internal static class VocabularyAnnotationsExtensions
{
/// <summary>
/// Gets Org.OData.Capabilities.V1.SearchRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.SearchRestrictions or null.</returns>
public static T GetRestrictions<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
where T : IRecord, new()
{
return model.GetRestrictionsImpl<T>(target, qualifiedName);
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.TopSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.TopSupported or null.</returns>
public static bool? GetTopSupported(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return GetSupported(model, target, CapabilitiesConstants.TopSupported);
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.SkipSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.SkipSupported or null.</returns>
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<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
where T : IRecord, new()
{
T restrictions = model.GetRecord<T>(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<T>(entityType, qualifiedName);
}
}
return restrictions;
}
}
}