Esempio n. 1
0
        public void CreateRefRequestBodies()
        {
            // Arrange
            ODataContext context = new ODataContext(_model);

            // Act
            var requestBodies = context.CreateRequestBodies();

            requestBodies.TryGetValue(Common.Constants.ReferencePostRequestBodyName, out Models.OpenApiRequestBody refPostBody);

            // Assert
            Assert.NotNull(refPostBody);
            Assert.Equal("New navigation property ref value", refPostBody.Description);
            Assert.Equal(Common.Constants.ReferenceCreateSchemaName, refPostBody.Content.First().Value.Schema.Reference.Id);
        }
        /// <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
            });
        }