Esempio n. 1
0
        /*
         * private static void ApplyAttribute(Operation operation, OperationFilterContext context, SwaggerClassMetaDataAttribute attribute)
         * {
         *  var key = attribute.StatusCode.ToString();
         *  Response response;
         *  if (!operation.Responses.TryGetValue(key, out response))
         *  {
         *      response = new Response();
         *  }
         *
         *  if (attribute.Description != null)
         *      response.Description = attribute.Description;
         *
         *  if (attribute.Type != null && attribute.Type != typeof(void))
         *      response.Schema = context.SchemaRegistry.GetOrRegister(attribute.Type);
         *
         *  operation.Responses[key] = response;
         * }
         *
         * private static SwaggerClassMetaDataAttribute[] GetActionAttributes(ApiDescription apiDesc)
         * {
         *  return apiDesc.ControllerAttributes().OfType<SwaggerClassMetaDataAttribute>().ToArray();
         * }
         */

        private static Type GetSuccessResponseType(OperationFilterContext context)
        {
            context.ApiDescription.TryGetMethodInfo(out var methodInfo);
            var declaringType = methodInfo.DeclaringType;
            var baseType      = declaringType.BaseType;
            var comparison    = typeof(QueryOnlyController <, , , , ,>);

            if (GenericHelpers.IsSubclassOfRawGeneric(comparison, baseType))
            {
                var genericArgs = baseType.GenericTypeArguments;
                return(genericArgs[3]);
            }

            return(null);
        }