Ejemplo n.º 1
0
        private static void VerifyExpandRestrictions(ExpandRestrictions expand)
        {
            Assert.NotNull(expand);

            Assert.NotNull(expand.Expandable);
            Assert.False(expand.Expandable.Value);

            Assert.NotNull(expand.NonExpandableProperties);
            Assert.Equal(2, expand.NonExpandableProperties.Count);
            Assert.Equal("abc|RelatedEvents", String.Join("|", expand.NonExpandableProperties));

            Assert.True(expand.IsNonExpandableProperty("RelatedEvents"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create $expand parameter for the <see cref="IEdmNavigationSource"/>.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <param name="target">The edm entity path.</param>
        /// <param name="entityType">The edm entity path.</param>
        /// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
        public static OpenApiParameter CreateExpand(this ODataContext context, IEdmVocabularyAnnotatable target, IEdmEntityType entityType)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(target, nameof(target));
            Utils.CheckArgumentNull(entityType, nameof(entityType));

            ExpandRestrictions expand = context.Model.GetExpandRestrictions(target);

            if (expand != null && !expand.IsExpandable)
            {
                return(null);
            }

            IList <IOpenApiAny> expandItems = new List <IOpenApiAny>
            {
                new OpenApiString("*")
            };

            foreach (var property in entityType.NavigationProperties())
            {
                if (expand != null && expand.IsNonExpandableProperty(property.Name))
                {
                    continue;
                }

                expandItems.Add(new OpenApiString(property.Name));
            }

            return(new OpenApiParameter
            {
                Name = "$expand",
                In = ParameterLocation.Query,
                Description = "Expand related entities",
                Schema = new OpenApiSchema
                {
                    Type = "array",
                    UniqueItems = true,
                    Items = new OpenApiSchema
                    {
                        Type = "string",
                        Enum = expandItems
                    }
                },
                Style = ParameterStyle.Simple
            });
        }