Пример #1
0
 private string GetSecurityAttribute(IOperationModel o)
 {
     if (o.HasStereotype("Secured") || Model.HasStereotype("Secured"))
     {
         var roles = o.GetStereotypeProperty <string>("Secured", "Roles");
         return(string.IsNullOrWhiteSpace(roles)
             ? "[Authorize]"
             : $"[Authorize(Roles = \"{roles}\")]");
     }
     return("[AllowAnonymous]");
 }
Пример #2
0
        private HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }
            if (operation.ReturnType == null || operation.Parameters.Any(x => x.TypeReference.Type == ReferenceType.ClassType))
            {
                return(HttpVerb.POST);
            }
            return(HttpVerb.GET);
        }
Пример #3
0
        private static HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }

            if (operation.ReturnType == null || operation.Parameters.Any(IsFromBody))
            {
                return(HttpVerb.POST);
            }

            return(HttpVerb.GET);
        }
        private HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }
            if (operation.ReturnType == null || operation.Parameters.Any(x => x.TypeReference.Type == ReferenceType.ClassType))
            {
                var hasIdParam = operation.Parameters.Any(x => x.Name.ToLower().EndsWith("id") && x.TypeReference.Type != ReferenceType.ClassType);
                if (hasIdParam && new[] { "delete", "remove" }.Any(x => operation.Name.ToLower().Contains(x)))
                {
                    return(HttpVerb.DELETE);
                }
                return(hasIdParam ? HttpVerb.PUT : HttpVerb.POST);
            }
            return(HttpVerb.GET);
        }
Пример #5
0
        private static bool RequiresPayloadObject(IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(false);
            }

            if (operation.GetStereotypeProperty("Http", "Payload", "AUTO") == "Payload Object")
            {
                return(true);
            }

            var verb = GetHttpVerb(operation);

            if (verb != HttpVerb.POST && verb != HttpVerb.PUT)
            {
                return(false);
            }

            return(operation.Parameters.Count(IsFromBody) > 1);
        }
        private string GetPath(IOperationModel operation)
        {
            var path = operation.GetStereotypeProperty <string>("Http", "Route")?.ToLower();

            return(path ?? operation.Name.ToLower());
        }