Search in sources :

Example 1 with ResourceIdParamView

use of com.google.api.codegen.viewmodel.ResourceIdParamView in project toolkit by googleapis.

the class PathTemplateTransformer method generateFormatResourceFunctions.

public List<FormatResourceFunctionView> generateFormatResourceFunctions(InterfaceContext context) {
    List<FormatResourceFunctionView> functions = new ArrayList<>();
    if (!context.getFeatureConfig().enableStringFormatFunctions()) {
        return functions;
    }
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    for (SingleResourceNameConfig resourceNameConfig : getSingleResourceNameConfigsUsedByInterface(context)) {
        FormatResourceFunctionView.Builder function = FormatResourceFunctionView.newBuilder().resourceName(namer.getResourceTypeName(resourceNameConfig)).entityName(resourceNameConfig.getEntityName().toLowerUnderscore()).name(namer.getFormatFunctionName(interfaceConfig, resourceNameConfig)).pathTemplateName(namer.getPathTemplateName(interfaceConfig, resourceNameConfig)).pathTemplateGetterName(namer.getPathTemplateNameGetter(interfaceConfig, resourceNameConfig)).pattern(resourceNameConfig.getNamePattern()).isResourceNameDeprecated(resourceNameConfig.getDeprecated());
        List<ResourceIdParamView> resourceIdParams = new ArrayList<>();
        for (String variable : resourceNameConfig.getNameTemplate().vars()) {
            ResourceIdParamView param = ResourceIdParamView.newBuilder().name(namer.getParamName(variable)).docName(namer.getParamDocName(variable)).templateKey(variable).build();
            resourceIdParams.add(param);
        }
        function.resourceIdParams(resourceIdParams);
        functions.add(function.build());
    }
    return functions;
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ResourceIdParamView(com.google.api.codegen.viewmodel.ResourceIdParamView) FormatResourceFunctionView(com.google.api.codegen.viewmodel.FormatResourceFunctionView) ArrayList(java.util.ArrayList) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Aggregations

InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 FormatResourceFunctionView (com.google.api.codegen.viewmodel.FormatResourceFunctionView)1 ResourceIdParamView (com.google.api.codegen.viewmodel.ResourceIdParamView)1 ArrayList (java.util.ArrayList)1