private RouteItem FindRouter(HttpRequest req)
        {
            string      path     = req.Path;
            RestfulVerb verb     = CastVerb(req.Method);
            string      cacheKey = string.Concat(path, ":", req.Method.ToLower());

            if (ROUTER_CACHE.ContainsKey(cacheKey))
            {
                return(ROUTER_CACHE[cacheKey]);
            }

            foreach (var router in this._routeOptions.Items)
            {
                // 没有配置Method标识匹配所有请求,否则必须匹配对应的Method
                if ((verb & router.AcceptVerb) != 0)
                {
                    var match = Match(router.Path, path);

                    if (!match)
                    {
                        continue;
                    }

                    ROUTER_CACHE.TryAdd(cacheKey, router);
                    return(router);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        private SwaggerMethod CreateSwaggerMethod(RestfulVerb verb)
        {
            SwaggerMethod m;

            switch (verb)
            {
            case  RestfulVerb.Get:
                m = new SwaggerGetMethod();
                break;

            case  RestfulVerb.Post:
                m = new SwaggerPostMethod();
                break;

            case  RestfulVerb.Put:
                m = new SwaggerPutMethod();
                break;

            case  RestfulVerb.Delete:
                m = new SwaggerDeleteMethod();
                break;

            case  RestfulVerb.Patch:
                m = new SwaggerPatchMethod();
                break;

            default:
                m = new SwaggerGetMethod();
                break;
            }
            return(m);
        }
Ejemplo n.º 3
0
        private void ProcessParameters(RestfulVerb verb, List <SwaggerApiParameters> pathParameters, ParameterInfo[] getParameters
                                       , Dictionary <string, SwaggerDefinition> definitions, SwaggerConfig config)
        {
            var parameter  = getParameters[0];
            var properties = parameter.ParameterType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            properties.ForEach(p =>
            {
                if (config.IngoreFields.Contains(p.Name))
                {
                    return;
                }

                SwaggerApiParameters apiParameter = new SwaggerApiParameters
                {
                    Name        = p.Name.ToCamelCase(),
                    Description = this._resolver.GetMemberInfoComment(p)
                };

                if (p.PropertyType == typeof(string) || p.PropertyType.IsValueType)
                {
                    apiParameter.Type = GetSwaggerType(p.PropertyType);
                    apiParameter.In   = verb == RestfulVerb.Any || verb == RestfulVerb.Get ? "query" : "formData";
                }
                else
                {
                    apiParameter.In     = verb == RestfulVerb.Any || verb == RestfulVerb.Get ? "query" : "body";
                    apiParameter.Schema = GetSwaggerItemSchema(p.PropertyType, definitions, config);
                }
                pathParameters.Add(apiParameter);
            });
        }
Ejemplo n.º 4
0
        private void ProcessParameters(RestfulVerb verb, List <SwaggerApiParameters> pathParameters, ParameterInfo[] getParameters
                                       , Dictionary <string, SwaggerDefinition> definitions)
        {
            var parameter  = getParameters[0];
            var properties = parameter.ParameterType.GetProperties();

            properties.ForEach(p =>
            {
                SwaggerApiParameters apiParameter = new SwaggerApiParameters
                {
                    Name        = p.Name.ToCamelCase(),
                    Description = this._resolver.GetMemberInfoComment(p)
                };

                if (p.PropertyType == typeof(string) || p.PropertyType.IsValueType)
                {
                    apiParameter.Type = GetSwaggerType(p.PropertyType);
                    apiParameter.In   = verb == RestfulVerb.Any || verb == RestfulVerb.Get ? "query" : "formData";
                }
                else
                {
                    apiParameter.In     = verb == RestfulVerb.Any || verb == RestfulVerb.Get ? "query" : "body";
                    apiParameter.Schema = GetSwaggerItemSchema(p.PropertyType, definitions);
                }
                pathParameters.Add(apiParameter);
            });
        }
Ejemplo n.º 5
0
 public RouterAttribute(string path, RestfulVerb acceptVerb = RestfulVerb.Any)
 {
     this.Path       = path;
     this.AcceptVerb = acceptVerb;
 }