use of com.google.api.codegen.config.GrpcStreamingConfig in project toolkit by googleapis.
the class TestCaseTransformer method createMockResponseAdditionalSubTrees.
private Iterable<InitCodeNode> createMockResponseAdditionalSubTrees(MethodContext context) {
List<InitCodeNode> additionalSubTrees = new ArrayList<>();
if (context.getMethodConfig().isPageStreaming()) {
// Initialize one resource element if it is page-streaming.
PageStreamingConfig config = context.getMethodConfig().getPageStreaming();
if (config.getResourcesFieldConfig().getFieldPath().size() == 1) {
String resourceFieldName = config.getResourcesFieldName();
additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
} else {
// Initialize all the objects between the response type and the resource element.
List<FieldModel> fieldGetters = Lists.reverse(config.getResourcesFieldConfig().getFieldPath());
InitCodeNode initCodeNode = null;
for (FieldModel field : fieldGetters) {
if (config.getResourcesField().isRepeated()) {
initCodeNode = InitCodeNode.createSingletonList(config.getResourcesFieldName());
} else {
initCodeNode = InitCodeNode.create(config.getResourcesFieldName());
}
InitCodeLineType lineType = field.isRepeated() ? ListInitLine : StructureInitLine;
initCodeNode = InitCodeNode.createWithChildren(field.getSimpleName(), lineType, initCodeNode);
}
additionalSubTrees.add(initCodeNode);
}
// Set the initial value of the page token to empty, in order to indicate that no more pages
// are available
String responseTokenName = config.getResponseTokenField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createWithValue(responseTokenName, InitValueConfig.createWithValue(InitValue.createLiteral(""))));
}
if (context.getMethodConfig().isBatching()) {
// Initialize one batching element if it is batching.
BatchingConfig config = context.getMethodConfig().getBatching();
if (config.getSubresponseField() != null) {
String subResponseFieldName = config.getSubresponseField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createSingletonList(subResponseFieldName));
}
}
if (context.getMethodConfig().isGrpcStreaming()) {
GrpcStreamingConfig streamingConfig = context.getMethodConfig().getGrpcStreaming();
if (streamingConfig.hasResourceField()) {
String resourceFieldName = streamingConfig.getResourcesField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
}
}
return additionalSubTrees;
}
use of com.google.api.codegen.config.GrpcStreamingConfig in project toolkit by googleapis.
the class NodeJSGapicSurfaceTransformer method createGrpcStreamingDescriptors.
private List<GrpcStreamingDetailView> createGrpcStreamingDescriptors(GapicInterfaceContext context) {
List<GrpcStreamingDetailView> result = new ArrayList<>();
for (MethodModel method : context.getGrpcStreamingMethods()) {
GrpcStreamingConfig grpcStreamingConfig = context.asDynamicMethodContext(method).getMethodConfig().getGrpcStreaming();
String resourcesFieldGetFunction = null;
if (grpcStreamingConfig.hasResourceField()) {
resourcesFieldGetFunction = context.getNamer().getFieldGetFunctionName(grpcStreamingConfig.getResourcesField());
}
result.add(GrpcStreamingDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).grpcStreamingType(grpcStreamingConfig.getType()).grpcResourcesField(resourcesFieldGetFunction).streamTypeName(context.getNamer().getStreamTypeName(grpcStreamingConfig.getType())).build());
}
return result;
}
use of com.google.api.codegen.config.GrpcStreamingConfig in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method createGrpcStreamingDescriptors.
private List<GrpcStreamingDetailView> createGrpcStreamingDescriptors(GapicInterfaceContext context) {
List<GrpcStreamingDetailView> result = new ArrayList<>();
for (MethodModel method : context.getGrpcStreamingMethods()) {
GrpcStreamingConfig grpcStreamingConfig = context.asDynamicMethodContext(method).getMethodConfig().getGrpcStreaming();
String resourcesFieldGetFunction = null;
if (grpcStreamingConfig.hasResourceField()) {
resourcesFieldGetFunction = context.getNamer().getFieldGetFunctionName(grpcStreamingConfig.getResourcesField());
}
result.add(GrpcStreamingDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).grpcStreamingType(grpcStreamingConfig.getType()).grpcResourcesField(resourcesFieldGetFunction).build());
}
return result;
}
Aggregations