Exemplo n.º 1
0
        public async Task When_complex_body_parameter_has_default_value_then_it_is_optional()
        {
            // Arrange
            var settings = new AspNetCoreToSwaggerGeneratorSettings();

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

            // Assert
            var operation = document.Operations.First(o => o.Operation.OperationId == "BodyParameters_RequiredComplexWithDefault").Operation;

            Assert.True(operation.ActualParameters.First().IsRequired);
        }
        public async Task When_model_binder_parameter_is_used_on_path_parameter_then_parameter_kind_is_path()
        {
            // Arrange
            var settings = new AspNetCoreToSwaggerGeneratorSettings {
                RequireParametersWithoutDefault = true
            };

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

            // Assert
            var kind = document.Operations.First().Operation.Parameters.First().Kind;

            Assert.Equal(SwaggerParameterKind.Path, kind);
        }
Exemplo n.º 3
0
        public async Task When_route_is_not_empty_then_path_starts_with_slash()
        {
            // Arrange
            var settings = new AspNetCoreToSwaggerGeneratorSettings();

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

            var json = document.ToJson();

            // Assert
            var operation = document.Operations.First(o => o.Operation.OperationId == "BodyParameters_RequiredPrimitive");

            Assert.StartsWith("/", operation.Path);
        }
Exemplo n.º 4
0
        public async Task When_route_is_empty_then_path_is_slash()
        {
            // Arrange
            var settings = new AspNetCoreToSwaggerGeneratorSettings();

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

            var json = document.ToJson();

            // Assert
            var operation = document.Operations.First(o => o.Operation.OperationId == "EmptyPath_Get");

            Assert.Equal("/", operation.Path);
        }
        public async Task When_generating_v1_then_only_v1_operations_are_included()
        {
            // Arrange
            var settings = new AspNetCoreToSwaggerGeneratorSettings();

            settings.ApiGroupNames = new[] { "1" };

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

            var json = document.ToJson();

            // Assert
            var operations = document.Operations;

            Assert.Equal(4, operations.Count());
            Assert.True(operations.All(o => o.Path.Contains("/v1/")));

            // VersionedIgnoredValues tag should not be in json document
            Assert.Equal(1, document.Tags.Count);
        }