Search in sources :

Example 36 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class PageStreamingMerger method generatePageStreamingRequestValueNode.

private ConfigNode generatePageStreamingRequestValueNode(ConfigNode parentNode, int startLine, MethodModel method) {
    String pageTokenName = pageStreamingTransformer.getNameForPageToken();
    String pageSizeName = pageStreamingTransformer.getNameForPageSize();
    boolean hasTokenField = method.getInputField(pageTokenName) != null;
    boolean hasPageSizeField = method.getInputField(pageSizeName) != null;
    ConfigNode requestValueNode = null;
    if (hasPageSizeField) {
        requestValueNode = FieldConfigNode.createStringPair(startLine, "page_size_field", pageSizeName);
        if (hasTokenField) {
            ConfigNode tokenFieldNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(requestValueNode), "token_field", pageTokenName);
            requestValueNode.insertNext(tokenFieldNode);
        }
    } else if (hasTokenField) {
        requestValueNode = FieldConfigNode.createStringPair(startLine, "token_field", pageTokenName);
    } else {
        return new NullConfigNode();
    }
    parentNode.setChild(requestValueNode);
    return requestValueNode;
}
Also used : NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 37 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class RetryMerger method generateRetryCodesDefValueNode.

private void generateRetryCodesDefValueNode(ConfigNode parentNode) {
    ConfigNode idempotentNode = generateRetryCodeDefNode(NodeFinder.getNextLine(parentNode), RETRY_CODES_IDEMPOTENT_NAME, ImmutableList.of(Status.Code.UNAVAILABLE.name(), Status.Code.DEADLINE_EXCEEDED.name()));
    parentNode.setChild(idempotentNode);
    ConfigNode nonIdempotentNode = generateRetryCodeDefNode(NodeFinder.getNextLine(idempotentNode), RETRY_CODES_NON_IDEMPOTENT_NAME, ImmutableList.<String>of());
    idempotentNode.insertNext(nonIdempotentNode);
}
Also used : ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 38 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class RetryMerger method generateRetryParamsDefValueNode.

private void generateRetryParamsDefValueNode(ConfigNode parentNode) {
    ConfigNode defaultNode = generateRetryParamDefNode(NodeFinder.getNextLine(parentNode), RETRY_PARAMS_DEFAULT_NAME);
    parentNode.setChild(defaultNode);
}
Also used : ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 39 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class DiscoGapicGeneratorApi method loadConfigFromFiles.

private static ConfigProto loadConfigFromFiles(List<String> configFileNames) {
    DiagCollector diagCollector = new SimpleDiagCollector();
    ConfigYamlReader yamlReader = new ConfigYamlReader();
    MessageGenerator messageGenerator = new MessageGenerator(ConfigProto.newBuilder());
    for (File file : pathsToFiles(configFileNames)) {
        ConfigHelper helper = new ConfigHelper(diagCollector, file.getName());
        ConfigNode configNode = yamlReader.generateConfigNode(file, helper);
        if (configNode == null) {
            continue;
        }
        messageGenerator.visit(configNode.getChild());
    }
    ConfigProto configProto = (ConfigProto) messageGenerator.getValue();
    if (configProto == null || configProto.equals(ConfigProto.getDefaultInstance())) {
        return null;
    }
    return configProto;
}
Also used : MessageGenerator(com.google.api.codegen.configgen.MessageGenerator) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector) DiagCollector(com.google.api.tools.framework.model.DiagCollector) ConfigHelper(com.google.api.codegen.configgen.ConfigHelper) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) File(java.io.File) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector) ConfigYamlReader(com.google.api.codegen.configgen.ConfigYamlReader)

Aggregations

ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)39 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)35 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)22 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)12 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)11 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)5 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)4 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)4 Node (org.yaml.snakeyaml.nodes.Node)4 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)3 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)3 ConfigHelper (com.google.api.codegen.configgen.ConfigHelper)2 ConfigYamlReader (com.google.api.codegen.configgen.ConfigYamlReader)2 MessageGenerator (com.google.api.codegen.configgen.MessageGenerator)2 File (java.io.File)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ProtoConfigMerger (com.google.api.codegen.configgen.mergers.ProtoConfigMerger)1