private ClientGeneratorMethod BuildClassMethod(string url, Method method, Resource resource) { var parentUrl = UrlGeneratorHelper.GetParentUri(url, resource.RelativeUri); var generatedMethod = new ClientGeneratorMethod { Name = NetNamingMapper.GetMethodName(method.Verb ?? "Get" + resource.RelativeUri), ReturnType = GetReturnType(GeneratorServiceHelper.GetKeyForResource(method, resource, parentUrl), method, resource, url), Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(method, resource, parentUrl), method, resource, url), Comment = GetComment(resource, method, url), Url = url, Verb = NetNamingMapper.Capitalize(method.Verb), Parent = null, UseSecurity = raml.SecuredBy != null && raml.SecuredBy.Any() || resource.Methods.Any(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()), RequestContentTypes = method.Body.Keys.ToArray(), ResponseContentTypes = method.Responses != null?method.Responses.Where(r => r.Body != null).SelectMany(r => r.Body.Keys).ToArray() : new string[0] }; // look in traits // look in resource types return(generatedMethod); }
private ClientGeneratorMethod BuildClassMethod(string url, Operation operation, RAML.Parser.Model.EndPoint resource, string modelsNamespace) { var parentUrl = UrlGeneratorHelper.GetParentUri(url, resource.Path); //TODO: check var responseContentTypes = operation.Responses != null? operation.Responses.Where(r => r.Payloads != null).SelectMany(r => r.Payloads).Select(p => p.MediaType).ToArray() : new string[0]; var generatedMethod = new ClientGeneratorMethod { ModelsNamespace = modelsNamespace, Name = NetNamingMapper.GetMethodName(operation.Method ?? "Get" + resource.Path), ReturnType = GetReturnType(operation, resource, url), Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(operation, resource), operation, resource, url), Comment = GetComment(resource, operation, url), Url = url, Verb = NetNamingMapper.Capitalize(operation.Method), Parent = null, UseSecurity = resource.Operations.Any(m => m.Method == operation.Method && m.Security != null && m.Security.Any()), RequestContentTypes = operation.ContentType, ResponseContentTypes = responseContentTypes }; // look in traits // look in resource types return(generatedMethod); }
private ControllerMethod BuildControllerMethod(string url, Operation method, Parser.Model.EndPoint resource, ControllerObject parent, IDictionary <string, Parameter> parentUriParameters, string modelsNamespace) { var relativeUri = UrlGeneratorHelper.GetRelativeUri(url, parent.PrefixUri); var parentUrl = UrlGeneratorHelper.GetParentUri(url, resource.Path); var operationWithSecurity = resource.Operations.FirstOrDefault(m => m.Method == method.Method && m.Security != null && m.Security.Any()); var securedBy = operationWithSecurity?.Security.Select(s => s.Name).ToArray(); return(new ControllerMethod { ModelsNamespace = modelsNamespace, Name = NetNamingMapper.GetMethodName(method.Method ?? "Get" + resource.Path), Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(method, resource), method, resource, url), UriParameters = uriParametersGenerator.GetUriParameters(resource, url, parentUriParameters), ResponseStatusCode = method.Responses != null && method.Responses.Count() == 1 ? method.Responses.First().StatusCode : null, ReturnType = GetReturnType(method, resource, url), Comment = GetComment(resource, method, url), Url = relativeUri, Verb = NetNamingMapper.Capitalize(method.Method), Parent = null, UseSecurity = resource.Operations.Any(m => m.Method == method.Method && m.Security != null && m.Security.Any()), SecuredBy = securedBy, SecurityParameters = GetSecurityParameters(method) }); }
private static Property ConvertGeneratorParamToProperty(GeneratorParameter p) { return(new Property { Name = NetNamingMapper.Capitalize(p.Name), OriginalName = p.Name, Description = p.Description, Type = p.Type, Required = true }); }
private ClientGeneratorMethod BuildClassMethod(string url, Method method, Resource resource, IDictionary <string, ApiObject> schemaRequestObjects, IDictionary <string, ApiObject> schemaResponseObjects) { var generatedMethod = new ClientGeneratorMethod { Name = NetNamingMapper.GetMethodName(method.Verb ?? "Get" + resource.RelativeUri), ReturnType = GetReturnType(GeneratorServiceHelper.GetKeyForResource(method, resource), method, resource, schemaResponseObjects), Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(method, resource), method, resource, schemaRequestObjects), Comment = GetComment(resource, method), Url = url, Verb = NetNamingMapper.Capitalize(method.Verb), Parent = null, UseSecurity = raml.SecuredBy != null && raml.SecuredBy.Any() || resource.Methods.Any(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()) }; return(generatedMethod); }
protected IEnumerable <GeneratorParameter> ExtractParametersFromUrl(string url) { var parameters = new List <GeneratorParameter>(); if (string.IsNullOrWhiteSpace(url) || !url.Contains("{")) { return(parameters); } var regex = new Regex("{([^}]+)}"); var matches = regex.Matches(url); parameters.AddRange(matches.Cast <Match>().Select(match => new GeneratorParameter { OriginalName = match.Groups[1].Value, Name = NetNamingMapper.Capitalize(NetNamingMapper.RemoveInvalidChars(match.Groups[1].Value)), Type = "string" }) .ToArray()); return(parameters); }
public IEnumerable <GeneratorParameter> GetUriParameters(EndPoint resource, string url, IDictionary <string, Parameter> parentUriParameters) { if (resource == null || resource.Parameters == null) { return(new List <GeneratorParameter>()); } var parameters = resource.Parameters.Where(p => p != null) .Select(p => new GeneratorParameter { OriginalName = p.Name, Name = NetNamingMapper.Capitalize(NetNamingMapper.RemoveInvalidChars(p.Name)), Type = p.Schema != null ? NewNetTypeMapper.GetNetType(p.Schema) : "string", Description = p.Description }) .ToList(); var urlParameters = ExtractParametersFromUrl(url).ToArray(); var distincUrlParameters = urlParameters.Where(up => parameters.All(p => up.Name != p.Name)).ToArray(); var matchedParameters = MatchParameters(parentUriParameters, distincUrlParameters); parameters.AddRange(matchedParameters); return(parameters); }
protected string GetUniqueObjectName(RAML.Parser.Model.EndPoint resource, RAML.Parser.Model.EndPoint parent) { string objectName; if (resource.Path.StartsWith("/{") && resource.Path.EndsWith("}")) { objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(resource)); } else { if (resource.Path == "/") { objectName = "RootUrl"; } else { objectName = NetNamingMapper.GetObjectName(resource.Path); } if (classesNames.Contains(objectName)) { objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(resource)); } } if (string.IsNullOrWhiteSpace(objectName)) { throw new InvalidOperationException("object name is null for " + resource.Path); } if (!classesNames.Contains(objectName)) { return(objectName); } if (parent == null || string.IsNullOrWhiteSpace(parent.Path)) { return(GetUniqueObjectName(objectName)); } if (resource.Path.StartsWith("/{") && parent.Path.EndsWith("}")) { objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(parent)) + objectName; } else { objectName = NetNamingMapper.GetObjectName(parent.Path) + objectName; if (classesNames.Contains(objectName)) { objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(parent)); } } if (string.IsNullOrWhiteSpace(objectName)) { throw new InvalidOperationException("object name is null for " + resource.Path); } if (!classesNames.Contains(objectName)) { return(objectName); } return(GetUniqueObjectName(objectName)); }
private static GeneratorParameter ConvertAmfParameterToGeneratorParameter(Parameter parameter) { return(new GeneratorParameter { OriginalName = parameter.Name, Name = NetNamingMapper.Capitalize(NetNamingMapper.RemoveInvalidChars(parameter.Name)), Type = NewNetTypeMapper.GetNetType(parameter.Schema), Description = parameter.Description }); }