private static IList <NavigationPropertyRestriction> GetRestrictedProperties(IEdmRecordExpression record)
        {
            if (record != null && record.Properties != null)
            {
                IEdmPropertyConstructor property = record.Properties.FirstOrDefault(p => p.Name == "RestrictedProperties");
                if (property != null)
                {
                    IEdmCollectionExpression value = property.Value as IEdmCollectionExpression;
                    if (value != null && value.Elements != null)
                    {
                        IList <NavigationPropertyRestriction> restrictedProperties = new List <NavigationPropertyRestriction>();
                        foreach (var item in value.Elements.OfType <IEdmRecordExpression>())
                        {
                            NavigationPropertyRestriction restriction = new NavigationPropertyRestriction();
                            restriction.Navigability       = item.GetEnum <NavigationType>("Navigability");
                            restriction.NavigationProperty = item.GetPropertyPath("NavigationProperty");
                            restrictedProperties.Add(restriction);
                        }

                        if (restrictedProperties.Any())
                        {
                            return(restrictedProperties);
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        ///  Get the collection of <typeparamref name="T"/> from the record using the given property name.
        /// </summary>
        /// <typeparam name="T">The element type.</typeparam>
        /// <param name="record">The record expression.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="elementAction">The element action.</param>
        /// <returns>The collection or null.</returns>
        public static IList <T> GetCollection <T>(this IEdmRecordExpression record, string propertyName, Action <T, IEdmExpression> elementAction)
            where T : new()
        {
            Utils.CheckArgumentNull(record, nameof(record));
            Utils.CheckArgumentNull(propertyName, nameof(propertyName));

            IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);

            if (property != null)
            {
                IEdmCollectionExpression collection = property.Value as IEdmCollectionExpression;
                if (collection != null && collection.Elements != null)
                {
                    IList <T> items = new List <T>();
                    foreach (var item in collection.Elements)
                    {
                        T a = new T();
                        elementAction(a, item);
                        items.Add(a);
                    }

                    return(items);
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Init the <see cref="CustomParameter"/>
        /// </summary>
        /// <param name="record">The input record.</param>
        public virtual void Init(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Name
            Name = record.GetString("Name");

            // Description
            Description = record.GetString("Description");

            // DocumentationURL
            DocumentationURL = record.GetString("DocumentationURL");

            // Required
            Required = record.GetBoolean("Required");

            // ExampleValues
            ExampleValues = record.GetCollection("ExampleValues", r =>
            {
                IEdmRecordExpression itemRecord = r as IEdmRecordExpression;
                if (itemRecord != null)
                {
                    return(Example.CreateExample(itemRecord));
                }

                return(null);
            });
        }
예제 #4
0
        protected override bool Initialize(IEdmVocabularyAnnotation annotation)
        {
            if (annotation == null ||
                annotation.Value == null ||
                annotation.Value.ExpressionKind != EdmExpressionKind.Record)
            {
                return(false);
            }

            IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;

            // Sortable
            Sortable = record.GetBoolean("Sortable");

            // AscendingOnlyProperties
            AscendingOnlyProperties = record.GetCollectionPropertyPath("AscendingOnlyProperties");

            // DescendingOnlyProperties
            DescendingOnlyProperties = record.GetCollectionPropertyPath("DescendingOnlyProperties");

            // NonSortablePropeties
            NonSortableProperties = record.GetCollectionPropertyPath("NonSortableProperties");

            return(true);
        }
예제 #5
0
        /// <summary>
        /// Create the corresponding Authorization object.
        /// </summary>
        /// <param name="record">The input record.</param>
        /// <returns>The created <see cref="Authorization"/> object.</returns>
        public static IEnumerable <Authorization> GetAuthorizations(this IEdmModel model, IEdmVocabularyAnnotatable target)
        {
            Utils.CheckArgumentNull(model, nameof(model));
            Utils.CheckArgumentNull(target, nameof(target));

            return(GetOrAddCached(model, target, AuthorizationConstants.Authorizations, () =>
            {
                IEdmTerm term = model.FindTerm(AuthorizationConstants.Authorizations);
                if (term != null)
                {
                    IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
                    if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection)
                    {
                        IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
                        if (collection.Elements != null)
                        {
                            return collection.Elements.Select(e =>
                            {
                                Debug.Assert(e.ExpressionKind == EdmExpressionKind.Record);

                                IEdmRecordExpression recordExpression = (IEdmRecordExpression)e;
                                Authorization auth = Authorization.CreateAuthorization(recordExpression);
                                return auth;
                            });
                        }
                    }
                }

                return null;
            }));
        }
예제 #6
0
        /// <summary>
        /// Init the <see cref="ExampleValue"/>
        /// </summary>
        /// <param name="record">The input record.</param>
        public virtual void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Description
            Description = record.GetString("Description");
        }
예제 #7
0
        /// <summary>
        /// Init the <see cref="ExternalExample"/>.
        /// </summary>
        /// <param name="record">The record.</param>
        public override void Init(IEdmRecordExpression record)
        {
            base.Init(record);

            // ExternalValue
            ExternalValue = record.GetString("ExternalValue");
        }
예제 #8
0
        /// <summary>
        /// Init the <see cref="HttpRequest"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public virtual void Init(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Description.
            Description = record.GetString("Description");

            // MethodDescription.
            MethodDescription = record.GetString("MethodDescription");

            // MethodType.
            MethodType = record.GetString("MethodType");

            // CustomQueryOptions
            CustomQueryOptions = record.GetCollection <CustomParameter>("CustomQueryOptions", (s, r) => s.Init(r as IEdmRecordExpression));

            // CustomHeaders
            CustomHeaders = record.GetCollection <CustomParameter>("CustomHeaders", (s, r) => s.Init(r as IEdmRecordExpression));

            // HttpResponses
            HttpResponses = record.GetCollection <HttpResponse>("HttpResponses", (s, r) => s.Init(r as IEdmRecordExpression));

            // SecuritySchemes
            SecuritySchemes = record.GetCollection <SecurityScheme>("SecuritySchemes", (s, r) => s.Init(r as IEdmRecordExpression));
        }
예제 #9
0
        /// <summary>
        /// Init the <see cref="DeleteRestrictionsType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Deletable
            Deletable = record.GetBoolean("Deletable");

            // NonDeletableNavigationProperties
            NonDeletableNavigationProperties = record.GetCollectionPropertyPath("NonDeletableNavigationProperties");

            // MaxLevels
            MaxLevels = (int?)record.GetInteger("MaxLevels");

            // FilterSegmentSupported
            FilterSegmentSupported = record.GetBoolean("FilterSegmentSupported");

            // TypecastSegmentSupported
            TypecastSegmentSupported = record.GetBoolean("TypecastSegmentSupported");

            // Permissions
            Permissions = record.GetCollection <PermissionType>("Permissions");

            // CustomHeaders
            CustomHeaders = record.GetCollection <CustomParameter>("CustomHeaders");

            // CustomQueryOptions
            CustomQueryOptions = record.GetCollection <CustomParameter>("CustomQueryOptions");

            // Description
            Description = record.GetString("Description");

            // LongDescription
            LongDescription = record.GetString("LongDescription");
        }
예제 #10
0
 /// <summary>
 /// Init the <see cref="RevisionsType"/>.
 /// </summary>
 /// <param name="record">The input record.</param>
 public virtual void Initialize(IEdmRecordExpression record)
 {
     Utils.CheckArgumentNull(record, nameof(record));
     Kind        = record.GetEnum <RevisionKind>(nameof(Kind));
     Version     = record.GetString(nameof(Version));
     Description = record.GetString(nameof(Description));
 }
예제 #11
0
        /// <summary>
        /// Init the <see cref="SelectSupportType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Supported
            Supported = record.GetBoolean("Supported");

            // Expandable
            InstanceAnnotationsSupported = record.GetBoolean("InstanceAnnotationsSupported");

            // Expandable
            Expandable = record.GetBoolean("Expandable");

            // Filterable
            Filterable = record.GetBoolean("Filterable");

            // Searchable
            Searchable = record.GetBoolean("Searchable");

            // TopSupported
            TopSupported = record.GetBoolean("TopSupported");

            // SkipSupported
            SkipSupported = record.GetBoolean("SkipSupported");

            // ComputeSupported
            ComputeSupported = record.GetBoolean("ComputeSupported");

            // Countable
            Countable = record.GetBoolean("Countable");

            // Sortable
            Sortable = record.GetBoolean("Sortable");
        }
        /// <summary>
        /// Get the collection of property path from the record using the given property name.
        /// </summary>
        /// <param name="record">The record expression.</param>
        /// <param name="propertyName">The property name.</param>
        /// <returns>The collection of property path or null.</returns>
        public static IList <string> GetCollectionPropertyPath(this IEdmRecordExpression record, string propertyName)
        {
            Utils.CheckArgumentNull(record, nameof(record));
            Utils.CheckArgumentNull(propertyName, nameof(propertyName));

            if (record.Properties != null)
            {
                IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
                if (property != null)
                {
                    IEdmCollectionExpression value = property.Value as IEdmCollectionExpression;
                    if (value != null && value.Elements != null)
                    {
                        IList <string> properties = new List <string>();
                        foreach (var a in value.Elements.Select(e => e as IEdmPathExpression))
                        {
                            properties.Add(a.Path);
                        }

                        if (properties.Any())
                        {
                            return(properties);
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Get the Enum value from the record using the given property name.
        /// </summary>
        /// <typeparam name="T">The output enum type.</typeparam>
        /// <param name="record">The record expression.</param>
        /// <param name="propertyName">The property name.</param>
        /// <returns>The Enum value or null.</returns>
        public static T?GetEnum <T>(this IEdmRecordExpression record, string propertyName)
            where T : struct
        {
            Utils.CheckArgumentNull(record, nameof(record));
            Utils.CheckArgumentNull(propertyName, nameof(propertyName));

            if (record.Properties != null)
            {
                IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
                if (property != null)
                {
                    IEdmEnumMemberExpression value = property.Value as IEdmEnumMemberExpression;
                    if (value != null && value.EnumMembers != null && value.EnumMembers.Any())
                    {
                        IEdmEnumMember member = value.EnumMembers.First();
                        T result;
                        if (Enum.TryParse(member.Name, out result))
                        {
                            return(result);
                        }
                    }
                }
            }

            return(null);
        }
예제 #14
0
        protected override bool Initialize(IEdmVocabularyAnnotation annotation)
        {
            if (annotation == null ||
                annotation.Value == null ||
                annotation.Value.ExpressionKind != EdmExpressionKind.Record)
            {
                return(false);
            }

            IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;

            // Filterable
            Filterable = record.GetBoolean("Filterable");

            // RequiresFilter
            RequiresFilter = record.GetBoolean("RequiresFilter");

            // RequiredProperties
            RequiredProperties = record.GetCollectionPropertyPath("RequiredProperties");

            // NonFilterableProperties
            NonFilterableProperties = record.GetCollectionPropertyPath("NonFilterableProperties");

            return(true);
        }
        /// <summary>
        /// Init the <see cref="SearchRestrictionsType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Searchable
            Searchable = record.GetBoolean("Searchable");

            // read the "UnsupportedExpressions"
            IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == "UnsupportedExpressions");

            if (property != null)
            {
                IEdmEnumMemberExpression value = property.Value as IEdmEnumMemberExpression;
                if (value != null && value.EnumMembers != null)
                {
                    SearchExpressions result;
                    foreach (var v in value.EnumMembers)
                    {
                        if (Enum.TryParse(v.Name, out result))
                        {
                            if (UnsupportedExpressions == null)
                            {
                                UnsupportedExpressions = result;
                            }
                            else
                            {
                                UnsupportedExpressions = UnsupportedExpressions | result;
                            }
                        }
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Init the <see cref="InlineExample"/>.
        /// </summary>
        /// <param name="record">The record.</param>
        public override void Init(IEdmRecordExpression record)
        {
            base.Init(record);

            // InlineValue
            InlineValue = record.GetString("InlineValue");
        }
        /// <summary>
        /// Get the collection of string from the record using the given property name.
        /// </summary>
        /// <param name="record">The record expression.</param>
        /// <param name="propertyName">The property name.</param>
        /// <returns>The collection of string or null.</returns>
        public static IList <string> GetCollection(this IEdmRecordExpression record, string propertyName)
        {
            Utils.CheckArgumentNull(record, nameof(record));
            Utils.CheckArgumentNull(propertyName, nameof(propertyName));

            IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);

            if (property != null)
            {
                IEdmCollectionExpression collection = property.Value as IEdmCollectionExpression;
                if (collection != null && collection.Elements != null)
                {
                    IList <string> items = new List <string>();
                    foreach (var item in collection.Elements)
                    {
                        IEdmStringConstantExpression itemRecord = item as IEdmStringConstantExpression;
                        items.Add(itemRecord.Value);
                    }

                    return(items);
                }
            }

            return(null);
        }
예제 #18
0
        /// <summary>
        /// Init the <see cref="ExternalExampleValue"/>
        /// </summary>
        /// <param name="record">The input record.</param>
        public override void Initialize(IEdmRecordExpression record)
        {
            // Load ExampleValue
            base.Initialize(record);

            // ExternalValue
            ExternalValue = record.GetString("ExternalValue");
        }
예제 #19
0
        /// <summary>
        /// Init <see cref="OAuth2Implicit"/>.
        /// </summary>
        /// <param name="record">the input record.</param>
        public override void Init(IEdmRecordExpression record)
        {
            // base checked.
            base.Init(record);

            // AuthorizationUrl
            AuthorizationUrl = record.GetString("AuthorizationUrl");
        }
예제 #20
0
        /// <summary>
        /// Init <see cref="OpenIDConnect"/>.
        /// </summary>
        /// <param name="record">the input record.</param>
        public override void Init(IEdmRecordExpression record)
        {
            // base checked.
            base.Init(record);

            // IssuerUrl
            IssuerUrl = record.GetString("IssuerUrl");
        }
        /// <summary>
        /// Init the <see cref="ReadRestrictionsType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public override void Initialize(IEdmRecordExpression record)
        {
            // Load base
            base.Initialize(record);

            // ReadByKeyRestrictions
            ReadByKeyRestrictions = record.GetRecord <ReadByKeyRestrictions>("ReadByKeyRestrictions");
        }
        /// <summary>
        /// Init <see cref="OAuth2ClientCredentials"/>.
        /// </summary>
        /// <param name="record">the input record.</param>
        public override void Init(IEdmRecordExpression record)
        {
            // base checked.
            base.Init(record);

            // TokenUrl
            TokenUrl = record.GetString("TokenUrl");
        }
예제 #23
0
        internal static bool TryAssertRecordAsType(this IEdmRecordExpression expression, IEdmTypeReference type, IEdmType context, bool matchExactly, out IEnumerable <EdmError> discoveredErrors)
        {
            EdmUtil.CheckArgumentNull(expression, "expression");
            EdmUtil.CheckArgumentNull(type, "type");

            if (!type.IsStructured())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.RecordExpressionNotValidForNonStructuredType, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionNotValidForNonStructuredType) };
                return(false);
            }

            HashSetInternal <string> foundProperties = new HashSetInternal <string>();
            List <EdmError>          errors          = new List <EdmError>();

            IEdmStructuredTypeReference structuredType = type.AsStructured();

            foreach (IEdmProperty typeProperty in structuredType.StructuredDefinition().Properties())
            {
                IEdmPropertyConstructor expressionProperty = expression.Properties.FirstOrDefault(p => p.Name == typeProperty.Name);
                if (expressionProperty == null)
                {
                    errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionMissingRequiredProperty, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionMissingProperty(typeProperty.Name)));
                }
                else
                {
                    IEnumerable <EdmError> recursiveErrors;
                    if (!expressionProperty.Value.TryAssertType(typeProperty.Type, context, matchExactly, out recursiveErrors))
                    {
                        foreach (EdmError error in recursiveErrors)
                        {
                            errors.Add(error);
                        }
                    }

                    foundProperties.Add(typeProperty.Name);
                }
            }

            if (!structuredType.IsOpen())
            {
                foreach (IEdmPropertyConstructor property in expression.Properties)
                {
                    if (!foundProperties.Contains(property.Name))
                    {
                        errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionHasExtraProperties, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionHasExtraProperties(property.Name)));
                    }
                }
            }

            if (errors.FirstOrDefault() != null)
            {
                discoveredErrors = errors;
                return(false);
            }

            discoveredErrors = Enumerable.Empty <EdmError>();
            return(true);
        }
예제 #24
0
        /// <summary>
        /// Create the corresponding Authorization object.
        /// </summary>
        /// <param name="record">The input record.</param>
        /// <returns>The created <see cref="Authorization"/> object.</returns>
        public static Authorization CreateAuthorization(IEdmRecordExpression record)
        {
            if (record == null || record.DeclaredType == null)
            {
                return(null);
            }

            IEdmComplexType complexType = record.DeclaredType.Definition as IEdmComplexType;

            if (complexType == null)
            {
                return(null);
            }

            Authorization auth;

            switch (complexType.FullTypeName())
            {
            case AuthorizationConstants.OpenIDConnect:     // OpenIDConnect
                auth = new OpenIDConnect();
                break;

            case AuthorizationConstants.Http:     // Http
                auth = new Http();
                break;

            case AuthorizationConstants.ApiKey:     // ApiKey
                auth = new ApiKey();
                break;

            case AuthorizationConstants.OAuth2ClientCredentials:     // OAuth2ClientCredentials
                auth = new OAuth2ClientCredentials();
                break;

            case AuthorizationConstants.OAuth2Implicit:     // OAuth2Implicit
                auth = new OAuth2Implicit();
                break;

            case AuthorizationConstants.OAuth2Password:     // OAuth2Password
                auth = new OAuth2Password();
                break;

            case AuthorizationConstants.OAuth2AuthCode:     // OAuth2AuthCode
                auth = new OAuth2AuthCode();
                break;

            case AuthorizationConstants.OAuthAuthorization:     // OAuthAuthorization
            default:
                throw new OpenApiException(String.Format(SRResource.AuthorizationRecordTypeNameNotCorrect, complexType.FullTypeName()));
            }

            if (auth != null)
            {
                auth.Initialize(record);
            }

            return(auth);
        }
예제 #25
0
 protected virtual void ProcessRecordExpression(IEdmRecordExpression expression)
 {
     this.ProcessExpression(expression);
     if (expression.DeclaredType != null)
     {
         this.VisitTypeReference(expression.DeclaredType);
     }
     this.VisitPropertyConstructors(expression.Properties);
 }
예제 #26
0
 /// <summary>
 /// Init the <see cref="DeprecatedRevisionsType"/>.
 /// </summary>
 /// <param name="record">The input record.</param>
 public override void Initialize(IEdmRecordExpression record)
 {
     base.Initialize(record);
     if (Kind != RevisionKind.Deprecated)
     {
         throw new InvalidOperationException("The kind of the revision must be Deprecated.");
     }
     RemovalDate = record.GetDateTime(nameof(RemovalDate));
     Date        = record.GetDateTime(nameof(Date));
 }
예제 #27
0
        /// <summary>
        /// Init the <see cref="SecurityScheme"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Init(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // AuthorizationSchemeName
            Authorization = record.GetString("Authorization");

            // RequiredScopes
            RequiredScopes = record.GetCollection("RequiredScopes");
        }
        /// <summary>
        /// Init the <see cref="PermissionType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // SchemeName
            SchemeName = record.GetString("SchemeName");

            // Scopes
            Scopes = record.GetCollection <ScopeType>("Scopes");
        }
        private static PermissionScopeData GetScopeData(IEdmRecordExpression scopeRecord)
        {
            var scopeProperty = scopeRecord.FindProperty("Scope")?.Value as IEdmStringConstantExpression;
            var restrictedPropertiesProperty = scopeRecord.FindProperty("RestrictedProperties")?.Value as IEdmStringConstantExpression;

            return(new PermissionScopeData()
            {
                Scope = scopeProperty?.Value, RestrictedProperties = restrictedPropertiesProperty?.Value
            });
        }
        /// <summary>
        /// Init the <see cref="NavigationRestrictionsType"/>.
        /// </summary>
        /// <param name="record">The input record.</param>
        public void Initialize(IEdmRecordExpression record)
        {
            Utils.CheckArgumentNull(record, nameof(record));

            // Navigability
            Navigability = record.GetEnum <NavigationType>("Navigability");

            // RestrictedProperties
            RestrictedProperties = record.GetCollection <NavigationPropertyRestriction>("RestrictedProperties");
        }
 private XObject GenerateRecordExpression(XNamespace ns, IEdmRecordExpression record)
 {
     var recordElement = new XElement(ns.GetName("Record"));
     foreach (var property in record.Properties)
     {
         var propertyValueElement = new XElement(ns.GetName("PropertyValue"));
         propertyValueElement.Add(new XAttribute("Property", property.Name));
         propertyValueElement.Add(GenerateValueExpression(ns, property.Value));
         recordElement.Add(propertyValueElement);
     }
     return recordElement;
 }