Exemple #1
0
        public void GetCustomAttribute_Should_ReturnCustomDerivedAttributes_When_FilteredOnDerived()
        {
            var actual = typeof(DerivedStub).GetMethods().SelectMany(x => CustomAttributeUtilities.GetCustomAttribute(x, typeof(HttpMethodAttribute)));

            actual.Should().HaveCount(1);
            actual.Should().Contain(x => x.GetType() == typeof(HttpGetAttribute))
            .And.NotContain(x => x.GetType() == typeof(HttpPostAttribute));
        }
Exemple #2
0
        public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
        {
            var derivedType = typeof(ODataController);

            foreach (var controllerType in Assembly.GetEntryAssembly().GetAllInstanceTypes(derivedType))
            {
                var controllerName = controllerType.Name.Replace("Controller", string.Empty);

                foreach (var methodInfo in controllerType.GetMethods()
                         .Where(x =>
                                CustomAttributeUtilities.GetCustomAttribute(x, typeof(HttpMethodAttribute)).Any() ||
                                CustomAttributeUtilities.GetCustomAttribute(x, typeof(EnableQueryAttribute)).Any()))
                {
                    var path = GetPath(Prefix, controllerType, methodInfo);

                    var operation = GetOperation(controllerName);

                    var schema   = context.SchemaRegistry.GetOrRegister(methodInfo.ReturnType);
                    var security = methodInfo.GetSecurityForOperation();

                    operation.SetOperation(schema, security);

                    try
                    {
                        swaggerDoc.Paths.Add(path, new PathItem()
                        {
                            Get = operation
                        });
                    }
                    catch (Exception exception)
                    {
                        Logger.LogError(exception, "Failed to add to swaggerDoc.");
                        Logger.LogError(exception.GetInnerMostException(), "Failed to add to swaggerDoc.");
                    }
                }
            }
        }
Exemple #3
0
        public void GetCustomAttribute_Should_ReturnNoCustomAttributes()
        {
            var actual = typeof(DerivedStub).GetMethods().SelectMany(x => CustomAttributeUtilities.GetCustomAttribute(x, new HttpPostAttribute()));

            actual.Should().BeEmpty();
        }