private bool IsUserScopedApi(ITypeInfo controller) { var route = controller.GetAttributes(TypeInfo.From <RouteAttribute>()).SingleOrDefault(); var template = (string)route?.AttributeData["Template"]; return(template?.StartsWith("v1/user/{userId}") ?? false); }
private string AppendRoutePrefix(string routeTemplate, ITypeInfo controllerType) { var routeAttribute = controllerType.GetAttributes(TypeInfo.From <RouteAttribute>()).SingleOrDefault(); var fullRoute = (routeAttribute == null ? "" : routeAttribute.AttributeData["Template"] + "/") + routeTemplate; if (IsUserScopedApi(controllerType)) { return(fullRoute.Substring("v1/user/{userId}/".Length)); } return(fullRoute.Substring("v1/".Length)); }
public static bool Accept(ITypeInfo type) { var test0 = From(typeof(int)); var test1 = From <Type>(); var test2 = TypeInfo.From <ControllerBase>(); var test3 = TypeInfo.From(typeof(void)); var test4 = SkbKontur.TypeScript.ContractGenerator.Internals.TypeInfo.From <string>(); var test5 = AnotherTypeInfo.From(typeof(Task <>)); return(TypeInfo.From <ControllerBase>().IsAssignableFrom(type)); }
protected virtual ITypeInfo ResolveReturnType(ITypeInfo typeInfo) { if (typeInfo.IsGenericType) { var genericTypeDefinition = typeInfo.GetGenericTypeDefinition(); if (genericTypeDefinition.Equals(TypeInfo.From(typeof(Task <>)))) { return(ResolveReturnType(typeInfo.GetGenericArguments()[0])); } } if (typeInfo.Equals(TypeInfo.From <Task>())) { return(TypeInfo.From(typeof(void))); } return(typeInfo); }
public ITypeBuildingContext ResolveType(string initialUnitPath, ITypeGenerator typeGenerator, ITypeInfo typeInfo, ITypeScriptUnitFactory unitFactory) { if (typeInfo.Equals(TypeInfo.From <MethodRootType>())) { return(new MethodTypeBuildingContext(unitFactory.GetOrCreateTypeUnit(initialUnitPath), typeInfo)); } if (CollectionTypeBuildingContext.Accept(typeInfo)) { return(new CollectionTypeBuildingContext(typeInfo)); } if (typeInfo.Equals(TypeInfo.From <TimeSpan>())) { return(new StringBuildingContext()); } if (typeInfo.IsAbstract) { return(new AbstractTypeBuildingContext(unitFactory.GetOrCreateTypeUnit(initialUnitPath), typeInfo)); } return(null); }
protected override BaseApiMethod ResolveBaseApiMethod(IMethodInfo methodInfo) { if (methodInfo.GetAttributes(TypeInfo.From <HttpGetAttribute>()).Any()) { return(BaseApiMethod.Get); } if (methodInfo.GetAttributes(TypeInfo.From <HttpPostAttribute>()).Any()) { return(BaseApiMethod.Post); } if (methodInfo.GetAttributes(TypeInfo.From <HttpPutAttribute>()).Any()) { return(BaseApiMethod.Put); } if (methodInfo.GetAttributes(TypeInfo.From <HttpDeleteAttribute>()).Any()) { return(BaseApiMethod.Delete); } throw new NotSupportedException($"Unresolved http verb for method {methodInfo.Name} at controller {methodInfo.DeclaringType?.Name}"); }
public static bool Accept(ITypeInfo type) { return(TypeInfo.From <ControllerBase>().IsAssignableFrom(type)); }
protected override IParameterInfo GetBody(IParameterInfo[] parameters, ITypeInfo controllerType) { return(parameters.SingleOrDefault(x => PassParameterToCall(x, controllerType) && x.GetAttributes(TypeInfo.From <FromBodyAttribute>()).Any())); }
protected override IParameterInfo[] GetQueryParameters(IParameterInfo[] parameters, ITypeInfo controllerType) { return(parameters.Where(x => PassParameterToCall(x, controllerType) && !x.GetAttributes(TypeInfo.From <FromBodyAttribute>()).Any()).ToArray()); }