Esempio n. 1
0
        private void VerifyCreateSelectParameter(IEdmElement edmElement, ODataContext context, string selectItemsText = null)
        {
            // Arrange & Act
            OpenApiParameter parameter;

            switch (edmElement)
            {
            case IEdmEntitySet entitySet:
                parameter = context.CreateSelect(entitySet);
                break;

            case IEdmSingleton singleton:
                parameter = context.CreateSelect(singleton);
                break;

            case IEdmNavigationProperty navigationProperty:
                parameter = context.CreateSelect(navigationProperty);
                break;

            default:
                return;
            }

            string itemsText = selectItemsText == null
                ? @"""type"": ""string"""
                : $@"{selectItemsText}
      ""type"": ""string""";

            // Assert
            Assert.NotNull(parameter);

            string json = parameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

            string expected = $@"{{
  ""name"": ""$select"",
  ""in"": ""query"",
  ""description"": ""Select properties to be returned"",
  ""style"": ""form"",
  ""explode"": false,
  ""schema"": {{
    ""uniqueItems"": true,
    ""type"": ""array"",
    ""items"": {{
      {itemsText}
    }}
  }}
}}";

            Assert.Equal(expected.ChangeLineBreaks(), json);
        }
Esempio n. 2
0
        public static OpenApiParameter CreateSelect(this ODataContext context, IEdmNavigationProperty navigationProperty)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(navigationProperty, nameof(navigationProperty));

            return(context.CreateSelect(navigationProperty, navigationProperty.ToEntityType()));
        }
Esempio n. 3
0
        public static OpenApiParameter CreateSelect(this ODataContext context, IEdmSingleton singleton)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(singleton, nameof(singleton));

            return(context.CreateSelect(singleton, singleton.EntityType()));
        }
Esempio n. 4
0
        public static OpenApiParameter CreateSelect(this ODataContext context, IEdmEntitySet entitySet)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(entitySet, nameof(entitySet));

            return(context.CreateSelect(entitySet, entitySet.EntityType()));
        }
 /// <summary>
 /// Create $select parameter for the <see cref="IEdmVocabularyAnnotatable"/>.
 /// </summary>
 /// <param name="context">The OData context.</param>
 /// <param name="target">The Edm target.</param>
 /// <param name="entityType">The Edm entity type.</param>
 /// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
 public static OpenApiParameter CreateSelect(this ODataContext context, IEdmVocabularyAnnotatable target, IEdmEntityType entityType)
 { // patchwork to avoid breaking changes
     return(context.CreateSelect(target, entityType as IEdmStructuredType));
 }