using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.AspNetCore.Tests.Web.Controllers.Parameters;

namespace NSwag.Generation.AspNetCore.Tests.Parameters
{
    public class HeaderParametersTests : AspNetCoreTestsBase
    {
        [Fact]
        public async Task When_complex_query_parameters_are_nullable_and_set_to_null_they_are_optional_in_spec()
        {
            // Arrange
            var settings = new AspNetCoreOpenApiDocumentGeneratorSettings
            {
                RequireParametersWithoutDefault = true,
                SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings
                {
                    SchemaType = SchemaType.OpenApi3
                }
            };

            // Act
            var document = await GenerateDocumentAsync(settings, typeof(HeaderParametersController));

            // Assert
            var operation = document.Operations.First().Operation;

            Assert.Equal(2, operation.ActualParameters.Count);
            Assert.True(operation.ActualParameters[0].IsRequired);
            Assert.False(operation.ActualParameters[operation.ActualParameters.Count - 1].IsRequired);
        }
    }
}