/// <summary>
        /// Converts <see cref="OpenApiResponseWithoutBodyAttribute"/> to <see cref="OpenApiResponse"/>.
        /// </summary>
        /// <param name="attribute"><see cref="OpenApiResponseWithoutBodyAttribute"/> instance.</param>
        /// <param name="namingStrategy"><see cref="NamingStrategy"/> instance to create the JSON schema from .NET Types.</param>
        /// <returns><see cref="OpenApiResponse"/> instance.</returns>
        public static OpenApiResponse ToOpenApiResponse(this OpenApiResponseWithoutBodyAttribute attribute, NamingStrategy namingStrategy = null)
        {
            attribute.ThrowIfNullOrDefault();

            var description = string.IsNullOrWhiteSpace(attribute.Description)
                                  ? "No description"
                                  : attribute.Description;
            var response = new OpenApiResponse()
            {
                Description = description,
            };

            if (!string.IsNullOrWhiteSpace(attribute.Summary))
            {
                var summary = new OpenApiString(attribute.Summary);

                response.Extensions.Add("x-ms-summary", summary);
            }

            if (attribute.HeaderType.HasInterface <IOpenApiResponseHeaderType>())
            {
                var header = Activator.CreateInstance(attribute.HeaderType) as IOpenApiResponseHeaderType;

                response.Headers = header.Headers;
            }

            return(response);
        }
Пример #2
0
        public void Given_Parameters_When_Instantiated_Then_It_Should_Return_Value()
        {
            var statusCode = HttpStatusCode.OK;
            var attribute  = new OpenApiResponseWithoutBodyAttribute(statusCode);

            attribute.StatusCode.Should().Be(statusCode);
            attribute.Summary.Should().BeNullOrWhiteSpace();
            attribute.Description.Should().BeNullOrWhiteSpace();
        }
Пример #3
0
        public void Given_Value_Property_Should_Return_Value()
        {
            var statusCode = HttpStatusCode.OK;
            var attribute  = new OpenApiResponseWithoutBodyAttribute(statusCode);

            attribute.StatusCode.Should().Be(statusCode);
            attribute.Summary.Should().BeNullOrWhiteSpace();
            attribute.Description.Should().BeNullOrWhiteSpace();
        }
Пример #4
0
        public void Given_Properties_When_Instantiated_Then_It_Should_Return_Value(string summary, string description, Type headerType)
        {
            var statusCode = HttpStatusCode.OK;
            var attribute  = new OpenApiResponseWithoutBodyAttribute(statusCode)
            {
                Summary          = summary,
                Description      = description,
                CustomHeaderType = headerType,
            };

            attribute.Summary.Should().Be(summary);
            attribute.Description.Should().Be(description);
            attribute.CustomHeaderType.Should().Be(headerType);
        }
        public void Given_Properties_When_ToOpenApiResponse_Invoked_Then_It_Should_Return_Value(string summary, string description, Type headerType)
        {
            var statusCode = HttpStatusCode.OK;
            var attribute  = new OpenApiResponseWithoutBodyAttribute(statusCode)
            {
                Summary          = summary,
                Description      = description,
                CustomHeaderType = headerType,
            };

            var result = OpenApiResponseWithoutBodyAttributeExtensions.ToOpenApiResponse(attribute);

            result.Description.Should().Be(description);
            result.Extensions.Should().ContainKey("x-ms-summary");
            (result.Extensions["x-ms-summary"] as OpenApiString).Value.Should().Be(summary);
            result.Headers.Should().ContainKey("x-fake-header");
        }
Пример #6
0
        /// <summary>
        /// Converts <see cref="OpenApiResponseWithoutBodyAttribute"/> to <see cref="OpenApiResponse"/>.
        /// </summary>
        /// <param name="attribute"><see cref="OpenApiResponseWithoutBodyAttribute"/> instance.</param>
        /// <param name="namingStrategy"><see cref="NamingStrategy"/> instance to create the JSON schema from .NET Types.</param>
        /// <returns><see cref="OpenApiResponse"/> instance.</returns>
        public static OpenApiResponse ToOpenApiResponse(this OpenApiResponseWithoutBodyAttribute attribute, NamingStrategy namingStrategy = null)
        {
            attribute.ThrowIfNullOrDefault();

            var description = string.IsNullOrWhiteSpace(attribute.Description)
                                  ? "No description"
                                  : attribute.Description;
            var response = new OpenApiResponse()
            {
                Description = description,
            };

            if (!string.IsNullOrWhiteSpace(attribute.Summary))
            {
                var summary = new OpenApiString(attribute.Summary);

                response.Extensions.Add("x-ms-summary", summary);
            }

            return(response);
        }