use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class MockServiceTransformer method createMockGrpcMethodViews.
public List<MockGrpcMethodView> createMockGrpcMethodViews(InterfaceContext context) {
if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableList.of();
}
List<MethodModel> methods = context.getInterfaceMethods();
ArrayList<MockGrpcMethodView> mocks = new ArrayList<>(methods.size());
for (MethodModel method : methods) {
if (context.getMethodConfig(method) == null) {
continue;
}
MethodContext methodContext = context.asRequestMethodContext(method);
String requestTypeName = method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
String responseTypeName = method.getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
MethodConfig methodConfig = methodContext.getMethodConfig();
mocks.add(MockGrpcMethodView.newBuilder().name(methodContext.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).requestTypeName(requestTypeName).responseTypeName(responseTypeName).grpcStreamingType(methodConfig.getGrpcStreamingType()).streamHandleTypeName(methodContext.getNamer().getStreamingServerName(method)).build());
}
return mocks;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateModifyMethods.
private List<ModifyMethodView> generateModifyMethods(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
List<ModifyMethodView> modifyMethods = new ArrayList<>();
Set<String> modifyTypeNames = new HashSet<>();
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodContext methodContext = context.asRequestMethodContext(method);
String inputTypeFullName = methodContext.getMethodModel().getInputFullName();
if (modifyTypeNames.contains(inputTypeFullName)) {
continue;
}
modifyTypeNames.add(inputTypeFullName);
MethodConfig methodConfig = methodContext.getMethodConfig();
ModifyMethodView.Builder builder = ModifyMethodView.builder();
builder.name(namer.getModifyMethodName(methodContext));
builder.requestTypeName(method.getAndSaveRequestTypeName(context.getImportTypeTable(), context.getNamer()));
builder.grpcStreamingType(methodConfig.getGrpcStreamingType());
modifyMethods.add(builder.build());
}
return modifyMethods;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class CSharpSurfaceNamer method getReturnDocLines.
@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
MethodConfig methodConfig = methodContext.getMethodConfig();
if (methodConfig.isPageStreaming()) {
FieldModel resourceType = methodConfig.getPageStreaming().getResourcesField();
String resourceTypeName = context.getImportTypeTable().getAndSaveNicknameForElementType(resourceType);
switch(synchronicity) {
case Sync:
return ImmutableList.of("A pageable sequence of <see cref=\"" + resourceTypeName + "\"/> resources.");
case Async:
return ImmutableList.of("A pageable asynchronous sequence of <see cref=\"" + resourceTypeName + "\"/> resources.");
}
} else if (methodConfig.isGrpcStreaming()) {
switch(methodConfig.getGrpcStreamingType()) {
case ServerStreaming:
return ImmutableList.of("The server stream.");
case BidiStreaming:
return ImmutableList.of("The client-server stream.");
default:
throw new IllegalStateException("Invalid streaming: " + methodConfig.getGrpcStreamingType());
}
} else {
boolean hasReturn = !methodConfig.getMethodModel().isOutputTypeEmpty();
switch(synchronicity) {
case Sync:
return hasReturn ? ImmutableList.of("The RPC response.") : ImmutableList.of();
case Async:
return ImmutableList.of(hasReturn ? "A Task containing the RPC response." : "A Task that completes when the RPC has completed.");
}
}
throw new IllegalStateException("Invalid Synchronicity: " + synchronicity);
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateApiMethods.
@VisibleForTesting
List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context, Iterable<MethodModel> methods) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : methods) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext methodContext = context.asRequestMethodContext(method);
if (method.getRequestStreaming() || method.getResponseStreaming()) {
apiMethods.add(apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(methodContext));
} else if (methodConfig.isPageStreaming()) {
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(methodContext));
} else if (methodConfig.isLongRunningOperation()) {
apiMethods.add(apiMethodTransformer.generateOperationRequestObjectMethod(methodContext));
} else {
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(methodContext));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateRetryConfigDefinitions.
@VisibleForTesting
List<RetryConfigDefinitionView> generateRetryConfigDefinitions(InterfaceContext context, List<MethodModel> methods) {
Set<RetryConfigDefinitionView.Name> retryNames = new HashSet<>();
for (MethodModel method : methods) {
MethodConfig conf = context.getMethodConfig(method);
retryNames.add(RetryConfigDefinitionView.Name.create(conf.getRetrySettingsConfigName(), conf.getRetryCodesConfigName()));
}
TreeMap<RetryConfigDefinitionView.Name, RetryConfigDefinitionView> retryDef = new TreeMap<>();
Map<String, ImmutableSet<String>> retryCodesDef = context.getInterfaceConfig().getRetryCodesDefinition();
Map<String, RetrySettings> retryParamsDef = context.getInterfaceConfig().getRetrySettingsDefinition();
for (RetryConfigDefinitionView.Name name : retryNames) {
ImmutableSet<String> codes = retryCodesDef.get(name.retryCodesConfigName());
if (codes.isEmpty()) {
continue;
}
List<String> retryCodeNames = new ArrayList<>();
for (String code : codes) {
retryCodeNames.add(context.getNamer().getStatusCodeName(code));
}
retryDef.put(name, RetryConfigDefinitionView.newBuilder().name(name).retryCodes(retryCodeNames).params(retryParamsDef.get(name.retrySettingsConfigName())).build());
}
if (!retryDef.isEmpty()) {
context.getImportTypeTable().saveNicknameFor("time;;;");
context.getImportTypeTable().saveNicknameFor("google.golang.org/grpc/codes;;;");
}
return new ArrayList<>(retryDef.values());
}
Aggregations