using Amazon.Lambda.Annotations.APIGateway;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
public static class TemplateParametersExtension
{
///
/// Returns aa of string containing template parameter
/// parsed from the .
///
/// this object.
public static HashSet GetTemplateParameters(this RestApiAttribute attribute)
{
var template = attribute.Template;
return GetTemplateParameters(template);
}
///
/// Returns aa of string containing template parameter
/// parsed from the .
///
/// this object.
public static HashSet GetTemplateParameters(this HttpApiAttribute attribute)
{
var template = attribute.Template;
return GetTemplateParameters(template);
}
private static HashSet GetTemplateParameters(string template)
{
var parameters = new HashSet();
var components = template.Split('/').Where(c => !string.IsNullOrWhiteSpace(c));
foreach (var component in components)
{
if (component.StartsWith("{") && component.EndsWith("}"))
{
var parameter = component.Substring(1, component.Length - 2);
parameters.Add(parameter);
}
}
return parameters;
}
}
}