public static HttpApiAttribute Build(AttributeData att) { if (att.ConstructorArguments.Length != 2) { throw new NotSupportedException($"{TypeFullNames.HttpApiAttribute} must have constructor with 2 arguments."); } var method = (LambdaHttpMethod)att.ConstructorArguments[0].Value; var template = att.ConstructorArguments[1].Value as string; var version = att.NamedArguments.FirstOrDefault(arg => arg.Key == "Version").Value.Value; var data = new HttpApiAttribute(method, template) { Version = version == null ? HttpApiVersion.V2 : (HttpApiVersion)version }; return(data); }
private static ApiEndpoint CreateApiEndpoint(MethodInfo methodInfo, HttpApiAttribute httpApiAttribute) { // TODO: Build argument list return(new ApiEndpoint( httpApiAttribute.HttpApiMethod, httpApiAttribute.Path, async(context, token, api) => { var parameters = BuildParameters(methodInfo, context, token).ToArray(); dynamic task = methodInfo.Invoke(api, parameters); try { return await task.ConfigureAwait(false); } catch (RuntimeBinderException e) when(e.Message.Contains("'void'")) { // TODO: Fix this as its ugly as hell! return null as dynamic; } })); }
private string ProcessHttpApiAttribute(ILambdaFunctionSerializable lambdaFunction, HttpApiAttribute httpApiAttribute) { var eventPath = $"Resources.{lambdaFunction.Name}.Properties.Events"; var methodName = httpApiAttribute.Method.ToString(); var methodPath = $"{eventPath}.Root{methodName}"; var version = httpApiAttribute.Version == HttpApiVersion.V1 ? "1.0" : "2.0"; _jsonWriter.SetToken($"{methodPath}.Type", "HttpApi"); _jsonWriter.SetToken($"{methodPath}.Properties.Path", httpApiAttribute.Template); _jsonWriter.SetToken($"{methodPath}.Properties.Method", methodName.ToUpper()); _jsonWriter.SetToken($"{methodPath}.Properties.PayloadFormatVersion", version); return($"Root{methodName}"); }
/// <summary> /// Returns aa <see cref="HashSet{T}"/> of string containing template parameter /// parsed from the <see cref="HttpApiAttribute.Template"/>. /// </summary> /// <param name="attribute">this <see cref="HttpApiAttribute"/> object.</param> public static HashSet <string> GetTemplateParameters(this HttpApiAttribute attribute) { var template = attribute.Template; return(GetTemplateParameters(template)); }