Beispiel #1
0
        public static APIOperation Create(string name,
                                          string method, string urlTemplate,
                                          ParameterContract[] parameters,
                                          RequestContract request, ResponseContract[] responses, string description = null)
        {
            RequestMethod requestMethod;

            if (method == "GET")
            {
                requestMethod = RequestMethod.GET;
            }
            else if (method == "POST")
            {
                requestMethod = RequestMethod.POST;
            }
            else if (method == "PUT")
            {
                requestMethod = RequestMethod.PUT;
            }
            else if (method == "DELETE")
            {
                requestMethod = RequestMethod.DELETE;
            }
            else if (method == "PATCH")
            {
                requestMethod = RequestMethod.PATCH;
            }
            else
            {
                throw new InvalidEntityException("Invalid operation's method");
            }

            return(Create(name, requestMethod, urlTemplate, parameters, request, responses, description));
        }
        public static APIOperation Create(string name,
                                          RequestMethod method, string urlTemplate,
                                          ParameterContract[] parameters,
                                          RequestContract request, ResponseContract[] responses, string description = null)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new InvalidEntityException("Operation's is required");
            }
            if (name.Length > 100)
            {
                throw new InvalidEntityException("Length of operation's name must be < 100");
            }
            if (String.IsNullOrWhiteSpace(urlTemplate))
            {
                throw new InvalidEntityException("Operation's urlTemplate is required");
            }


            APIOperation operation = new APIOperation();

            operation.Id                 = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.APIOPERATION);
            operation.Name               = name;
            operation.Method             = method.ToString();
            operation.TemplateParameters = parameters;
            operation.Request            = request;
            operation.Responses          = responses;
            operation.Description        = description;

            operation.UrlTemplate = urlTemplate;
            //operation.UrlTemplate = APIOperationHelper.BuildURL(urlTemplate, parameters);

            return(operation);
        }
        public static RequestContract Create(string description                      = null,
                                             ParameterContract[] headers             = null,
                                             ParameterContract[] queryParameters     = null,
                                             RepresentationContract[] represenations = null)
        {
            RequestContract e = new RequestContract();

            e.Description     = description;
            e.QueryParameters = queryParameters;
            e.Headers         = headers;
            e.Representations = represenations;
            return(e);
        }