Exemple #1
0
        /// <summary>
        /// Create the list of <see cref="OpenApiParameter"/> for a <see cref="IEdmFunctionImport"/>.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <param name="functionImport">The Edm function import.</param>
        /// <returns>The created list of <see cref="OpenApiParameter"/>.</returns>
        public static IList <OpenApiParameter> CreateParameters(this ODataContext context, IEdmFunctionImport functionImport)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(functionImport, nameof(functionImport));

            return(context.CreateParameters(functionImport.Function));
        }
        public void CreateParametersThrowArgumentNullContext()
        {
            // Arrange
            ODataContext context = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>("context", () => context.CreateParameters());
        }
        public void CreateParametersReturnsCreatedParameters()
        {
            // Arrange
            IEdmModel    model   = EdmCoreModel.Instance;
            ODataContext context = new ODataContext(model);

            // Act
            var parameters = context.CreateParameters();

            // Assert
            Assert.NotNull(parameters);
            Assert.NotEmpty(parameters);
            Assert.Equal(5, parameters.Count);
            Assert.Equal(new[] { "top", "skip", "count", "filter", "search" },
                         parameters.Select(p => p.Key));
        }
        /// <summary>
        /// Create a <see cref="OpenApiComponents"/>.
        /// The value of components is a Components Object.
        /// It holds maps of reusable schemas describing message bodies, operation parameters, and responses.
        /// </summary>
        /// <param name="context">The OData to Open API context.</param>
        /// <returns>The created <see cref="OpenApiComponents"/> object.</returns>
        public static OpenApiComponents CreateComponents(this ODataContext context)
        {
            Utils.CheckArgumentNull(context, nameof(context));

            // "components": {
            //   "schemas": …,
            //   "parameters": …,
            //   "responses": …,
            //   "requestBodies": …
            //  }
            return(new OpenApiComponents
            {
                // The value of schemas is a map of Schema Objects.
                // Each entity type, complex type, enumeration type, and type definition directly
                // or indirectly used in the paths field is represented as a name/value pair of the schemas map.
                Schemas = context.CreateSchemas(),

                // The value of parameters is a map of Parameter Objects.
                // It allows defining query options and headers that can be reused across operations of the service.
                Parameters = context.CreateParameters(),

                // The value of responses is a map of Response Objects.
                // It allows defining responses that can be reused across operations of the service.
                Responses = context.CreateResponses(),

                // The value of requestBodies is a map of RequestBody Objects.
                // It allows refining request bodies that can be reused across operations of the service.
                RequestBodies = context.CreateRequestBodies(),

                Examples = context.CreateExamples(),

                SecuritySchemes = context.CreateSecuritySchemes(),

                // Make others as null.
                Links = null,

                Callbacks = null,

                Extensions = null
            });
        }
        public void CanSeralizeAsYamlFromTheCreatedParameters()
        {
            // Arrange
            IEdmModel    model   = EdmCoreModel.Instance;
            ODataContext context = new ODataContext(model);

            // Act
            var parameters = context.CreateParameters();

            // Assert
            Assert.Contains("skip", parameters.Select(p => p.Key));
            var skip = parameters.First(c => c.Key == "skip").Value;

            string yaml = skip.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);

            Assert.Equal(
                @"name: $skip
in: query
description: Skip the first n items
schema:
  minimum: 0
  type: integer
".ChangeLineBreaks(), yaml);
        }