Beispiel #1
0
 private void InsertOPerationInPathItem(PathItemObject pi, string verb, OperationObject operationObj)
 {
     if (verb == "get")
     {
         pi.Get = operationObj;
     }
     else if (verb == "post")
     {
         pi.Post = operationObj;
     }
     else if (verb == "put")
     {
         pi.Put = operationObj;
     }
     else if (verb == "delete")
     {
         pi.Delete = operationObj;
     }
     else if (verb == "head")
     {
         pi.Head = operationObj;
     }
     else if (verb == "options")
     {
         pi.Options = operationObj;
     }
     else if (verb == "patch")
     {
         pi.Patch = operationObj;
     }
 }
Beispiel #2
0
        public void Build()
        {
            PathsObject = new PathsObject();

            foreach (ServiceDescriptor service in Services)
            {
                if (IsControllerBase(service.ServiceType))
                {
                    var ty             = service.ServiceType;
                    var controllerAtrs = ty.GetCustomAttributes();
                    var methods        = ty.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                    foreach (MethodInfo methInf in methods)
                    {
                        var methodAtrs = methInf.GetCustomAttributes();
                        if (IsOperation(methInf, methodAtrs))
                        {
                            var pathSegment  = BuildPathSegment(ty, controllerAtrs, methodAtrs);
                            var verb         = GetVerb(methodAtrs);
                            var operationObj = BuildOperationObject(controllerAtrs, methInf, methodAtrs);
                            if (operationObj != null)
                            {
                                PathItemObject pi;
                                if (PathsObject.ContainsKey(pathSegment))
                                {
                                    pi = PathsObject[pathSegment];
                                }
                                else
                                {
                                    pi = new PathItemObject();
                                    PathsObject[pathSegment] = pi;
                                }
                                InsertOPerationInPathItem(pi, verb, operationObj);
                            }
                        }
                    }
                }
            }
            if (DefineSchemasFor.Keys.Count > 0)
            {
                ComponetsObject         = new ComponetsObject();
                ComponetsObject.Schemas = new Dictionary <string, SchemaObject>();
                foreach (string key in DefineSchemasFor.Keys)
                {
                    ComponetsObject.Schemas[key] = DeriveSchemaForType(DefineSchemasFor[key]);
                }
            }
        }