use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class GapicInterfaceContext method createGrpcRerouteMap.
private static Map<Interface, Interface> createGrpcRerouteMap(Model model, GapicProductConfig productConfig) {
HashMap<Interface, Interface> grpcRerouteMap = new HashMap<>();
for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
if (!apiInterface.isReachable()) {
continue;
}
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
String reroute = methodConfig.getRerouteToGrpcInterface();
if (!Strings.isNullOrEmpty(reroute)) {
Interface targetInterface = model.getSymbolTable().lookupInterface(reroute);
grpcRerouteMap.put(targetInterface, apiInterface);
}
}
}
return grpcRerouteMap;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class LongRunningTransformer method generateDetailView.
LongRunningOperationDetailView generateDetailView(MethodContext context) {
MethodConfig methodConfig = context.getMethodConfig();
LongRunningConfig lroConfig = methodConfig.getLongRunningConfig();
SurfaceNamer namer = context.getNamer();
String clientReturnTypeName = namer.getAndSaveOperationResponseTypeName(context.getMethodModel(), context.getTypeTable(), methodConfig);
String operationPayloadTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getReturnType());
String metadataTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getMetadataType());
return LongRunningOperationDetailView.newBuilder().methodName(namer.getApiMethodName(context.getMethodModel(), VisibilityConfig.PUBLIC)).constructorName(namer.getTypeConstructor(clientReturnTypeName)).clientReturnTypeName(clientReturnTypeName).operationPayloadTypeName(operationPayloadTypeName).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(metadataTypeName).implementsDelete(lroConfig.implementsDelete()).implementsCancel(lroConfig.implementsCancel()).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class MockServiceTransformer method getGrpcInterfacesForService.
public Map<String, InterfaceModel> getGrpcInterfacesForService(ApiModel model, GapicProductConfig productConfig, InterfaceModel apiInterface) {
if (!productConfig.getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableMap.of();
}
Map<String, InterfaceModel> interfaces = new LinkedHashMap<>();
interfaces.put(apiInterface.getFullName(), apiInterface);
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
String reroute = methodConfig.getRerouteToGrpcInterface();
if (!Strings.isNullOrEmpty(reroute)) {
InterfaceModel targetInterface = model.getInterface(reroute);
interfaces.put(reroute, targetInterface);
}
}
return interfaces;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PageStreamingTransformer method generateDescriptor.
public PageStreamingDescriptorView generateDescriptor(InterfaceContext context, MethodModel method) {
MethodConfig methodConfig = context.getMethodConfig(method);
PageStreamingConfig pageStreaming = methodConfig.getPageStreaming();
PageStreamingDescriptorView.Builder descriptor = PageStreamingDescriptorView.newBuilder();
descriptor.varName(context.getNamer().getPageStreamingDescriptorName(method));
descriptor.requestTokenFieldName(context.getNamer().getRequestTokenFieldName(pageStreaming));
descriptor.requestTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getRequestTokenField()));
descriptor.requestTokenSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
if (pageStreaming.hasPageSizeField()) {
descriptor.requestPageSizeFieldName(context.getNamer().getPageSizeFieldName(pageStreaming));
descriptor.requestPageSizeGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getPageSizeField()));
descriptor.requestPageSizeSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getPageSizeField()));
}
descriptor.responseTokenFieldName(context.getNamer().getResponseTokenFieldName(pageStreaming));
descriptor.responseTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
descriptor.resourcesFieldName(context.getNamer().getResourcesFieldName(pageStreaming));
descriptor.resourcesGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResourcesField()));
descriptor.methodName(context.getNamer().getMethodKey(method));
descriptor.transportMethodName(context.getNamer().getGrpcMethodName(method));
return descriptor.build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PathTemplateTransformer method getSingleResourceNameConfigsUsedByInterface.
private List<SingleResourceNameConfig> getSingleResourceNameConfigsUsedByInterface(InterfaceContext context) {
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
Set<String> foundSet = new HashSet<>();
ImmutableList.Builder<SingleResourceNameConfig> resourceNameConfigsBuilder = ImmutableList.builder();
for (SingleResourceNameConfig config : interfaceConfig.getSingleResourceNameConfigs()) {
resourceNameConfigsBuilder.add(config);
foundSet.add(config.getEntityId());
}
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
MethodContext methodContext = context.asRequestMethodContext(methodConfig.getMethodModel());
for (String fieldNamePattern : methodConfig.getFieldNamePatterns().values()) {
SingleResourceNameConfig resourceNameConfig = methodContext.getSingleResourceNameConfig(fieldNamePattern);
if (resourceNameConfig != null && !foundSet.contains(resourceNameConfig.getEntityId())) {
resourceNameConfigsBuilder.add(resourceNameConfig);
foundSet.add(resourceNameConfig.getEntityId());
}
}
}
return resourceNameConfigsBuilder.build();
}
Aggregations