Пример #1
0
        private StringBuilder SetResponses(StringBuilder RAML, RouteModel route)
        {
            if (route.Responses == null ||
                route.Responses.Count <= 0 ||
                route.Responses.All(p => String.IsNullOrEmpty(p.ContentType)))
            {
                return(RAML);
            }

            RAML.AppendFormat("    responses:{0}", _newLine);
            foreach (var response in route.Responses)
            {
                RAML.AppendFormat("      {0}:{1}", (int)response.StatusCode, _newLine);
                if (!String.IsNullOrEmpty(response.Description))
                {
                    RAML.AppendFormat("        description: |{1}          {0}{1}", response.Description, _newLine);
                }
                RAML.AppendFormat("        body:{0}", _newLine);
                RAML.AppendFormat("          {0}: {1}", response.ContentType, _newLine);
                if (!String.IsNullOrEmpty(response.Example))
                {
                    RAML.AppendFormat("            example: |{1}                {0}{1}", response.Example, _newLine);
                }
            }
            return(RAML);
        }
Пример #2
0
 private StringBuilder SetRoutes(StringBuilder RAML, RouteModel route)
 {
     RAML = SetUriParameters(RAML, route);
     RAML = SetHttpVerb(RAML, route);
     RAML = SetDescription(RAML, route);
     RAML = SetRequest(RAML, route);
     RAML = SetHeaders(RAML, route);
     RAML = SetParameters(RAML, route);
     RAML = SetResponses(RAML, route);
     return(RAML);
 }
Пример #3
0
        private StringBuilder SetHeaders(StringBuilder RAML, RouteModel route)
        {
            if (route.Headers == null ||
                route.Headers.Count <= 0 ||
                route.Headers.All(p => String.IsNullOrEmpty(p.Name)))
            {
                return(RAML);
            }

            RAML.AppendFormat("    headers:{0}", _newLine);
            return(route.Headers.Aggregate(RAML, SetHeaderDetails));
        }
Пример #4
0
        public RAMLModel WebApiToRamlModel(Uri baseUri, string title, string version, string defaultMediaTypes, string description)
        {
            var model = new RAMLModel
            {
                BaseUri = baseUri, //new Uri("http://www.google.com"),
                Title = title, //"Super web api",
                Version = version, //"1"
                DefaultMediaType = defaultMediaTypes,
                Description = description,
                Routes = new List<RouteModel>()
            };

            foreach (var api in _apiDescriptions)
            {
                IEnumerable<RequestHeadersAttribute> headers = null;
                IEnumerable<ResponseBodyAttribute> responseBody = null;

                if(api.ActionDescriptor != null)
                {
                    headers = api.ActionDescriptor.GetCustomAttributes<RequestHeadersAttribute>();
                    responseBody = api.ActionDescriptor.GetCustomAttributes<ResponseBodyAttribute>();
                }

                var routeModel = new RouteModel
                {
                    Verb = api.HttpMethod.Method.ToLower(),
                    UrlTemplate = api.RelativePath,
                    Headers = GetHeaders(headers),
                    //QueryParameters = GetQueryParameters(api),
                    BodyParameters = GetBodyParameters(api),
                    UriParameters = GetUriParameters(api),
                    Responses = GetResponseBodies(responseBody),
                    Description = api.Documentation
                };

                if (routeModel.Verb == "put" || routeModel.Verb == "post")
                {
                    routeModel.RequestContentType = "application/x-www-form-urlencoded:";
                }

                model.Routes.Add(routeModel);
            }

            return model;
        }
Пример #5
0
        private StringBuilder SetUriParameters(StringBuilder RAML, RouteModel route)
        {
            if (route.UriParameters == null || route.UriParameters.Count <= 0)
            {
                return(RAML);
            }

            RAML.AppendFormat("  uriParameters: {0}", _newLine);
            foreach (var parameters in route.UriParameters)
            {
                RAML.AppendFormat("      {0}: {1}", parameters.Name, _newLine);
                RAML.AppendFormat("        type: {0}{1}", parameters.Type.ToRamlType(), _newLine);
                RAML.AppendFormat("        required: {0}{1}", parameters.IsRequired.ToString().ToLower(), _newLine);
                RAML.AppendFormat("        description: {0}{1}", parameters.Description, _newLine);
                RAML.AppendFormat("        example: |{1}            {0}{1}", parameters.Example, _newLine);
            }
            return(RAML);
        }
Пример #6
0
        private StringBuilder SetRequest(StringBuilder RAML, RouteModel route)
        {
            if (route.BodyParameters == null || route.BodyParameters.Count == 0)
            {
                return(RAML);
            }

            RAML.AppendFormat("    body:{0}", _newLine);
            RAML.AppendFormat("      {0}: {1}", route.RequestContentType, _newLine);
            RAML.AppendFormat("        formParameters: {0}", _newLine);

            foreach (var r in route.BodyParameters)
            {
                RAML.AppendFormat("          {0}: {1}", r.Name, _newLine);
                RAML.AppendFormat("            description  : {0}{1}", r.Description, _newLine);
                RAML.AppendFormat("            type  : {0}{1}", r.Type.ToRamlType(), _newLine);
                RAML.AppendFormat("            required  : {0}{1}", r.IsRequired.ToString().ToLower(), _newLine);
                RAML.AppendFormat("            example  : {0}{1}", r.Example, _newLine);
            }
            return(RAML);
        }
Пример #7
0
 private StringBuilder SetHttpVerb(StringBuilder RAML, RouteModel route)
 {
     RAML.AppendFormat("  {0}:{1}", route.Verb, _newLine);
     return(RAML);
 }
Пример #8
0
 private StringBuilder SetDescription(StringBuilder RAML, RouteModel route)
 {
     RAML.AppendFormat("    description: {0}{1}", route.Description, _newLine);
     return(RAML);
 }
Пример #9
0
 private StringBuilder SetDescription(StringBuilder RAML, RouteModel route)
 {
     RAML.AppendFormat("    description: {0}{1}", route.Description, _newLine);
     return RAML;
 }
Пример #10
0
        private StringBuilder SetHeaders(StringBuilder RAML, RouteModel route)
        {
            if (route.Headers == null ||
                route.Headers.Count <= 0 ||
                route.Headers.All(p => String.IsNullOrEmpty(p.Name))) return RAML;

            RAML.AppendFormat("    headers:{0}", _newLine);
            return route.Headers.Aggregate(RAML, SetHeaderDetails);
        }
Пример #11
0
        private StringBuilder SetUriParameters(StringBuilder RAML, RouteModel route)
        {
            if (route.UriParameters == null || route.UriParameters.Count <= 0) return RAML;

            RAML.AppendFormat("  uriParameters: {0}", _newLine);
            foreach (var parameters in route.UriParameters)
            {
                RAML.AppendFormat("      {0}: {1}", parameters.Name, _newLine);
                RAML.AppendFormat("        type: {0}{1}", parameters.Type.ToRamlType(), _newLine);
                RAML.AppendFormat("        required: {0}{1}", parameters.IsRequired.ToString().ToLower(), _newLine);
                RAML.AppendFormat("        description: {0}{1}", parameters.Description, _newLine);
                RAML.AppendFormat("        example: |{1}            {0}{1}", parameters.Example, _newLine);
            }
            return RAML;
        }
Пример #12
0
 private StringBuilder SetRoutes(StringBuilder RAML, RouteModel route)
 {
     RAML = SetUriParameters(RAML, route);
     RAML = SetHttpVerb(RAML, route);
     RAML = SetDescription(RAML, route);
     RAML = SetRequest(RAML, route);
     RAML = SetHeaders(RAML, route);
     RAML = SetParameters(RAML, route);
     RAML = SetResponses(RAML, route);
     return RAML;
 }
Пример #13
0
        private StringBuilder SetResponses(StringBuilder RAML, RouteModel route)
        {
            if (route.Responses == null ||
                route.Responses.Count <= 0 ||
                route.Responses.All(p => String.IsNullOrEmpty(p.ContentType))) return RAML;

            RAML.AppendFormat("    responses:{0}", _newLine);
            foreach (var response in route.Responses)
            {
                RAML.AppendFormat("      {0}:{1}", (int)response.StatusCode, _newLine);
                if (!String.IsNullOrEmpty(response.Description))
                {
                    RAML.AppendFormat("        description: |{1}          {0}{1}", response.Description, _newLine);
                }
                RAML.AppendFormat("        body:{0}", _newLine);
                RAML.AppendFormat("          {0}: {1}", response.ContentType, _newLine);
                RAML.AppendFormat("            schema: {0}{1}", response.Schema, _newLine);
                if (!String.IsNullOrEmpty(response.Example))
                {
                    RAML.AppendFormat("            example: |{1}                {0}{1}", response.Example, _newLine);
                }
            }
            return RAML;
        }
Пример #14
0
        private StringBuilder SetRequest(StringBuilder RAML, RouteModel route)
        {
            if (route.BodyParameters == null || route.BodyParameters.Count == 0 ) return RAML;

            RAML.AppendFormat("    body:{0}", _newLine);
            RAML.AppendFormat("      {0}: {1}", route.RequestContentType, _newLine);
            RAML.AppendFormat("        formParameters: {0}", _newLine);

            foreach (var r in route.BodyParameters)
            {
                RAML.AppendFormat("          {0}: {1}", r.Name, _newLine);
                RAML.AppendFormat("            description  : {0}{1}", r.Description, _newLine);
                RAML.AppendFormat("            type  : {0}{1}", r.Type.ToRamlType(), _newLine);
                RAML.AppendFormat("            required  : {0}{1}", r.IsRequired.ToString().ToLower(), _newLine);
                RAML.AppendFormat("            example  : {0}{1}", r.Example, _newLine);
            }
            return RAML;
        }
Пример #15
0
 private StringBuilder SetHttpVerb(StringBuilder RAML, RouteModel route)
 {
     RAML.AppendFormat("  {0}:{1}", route.Verb, _newLine);
     return RAML;
 }