use of com.google.api.codegen.config.MethodModel 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());
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
MethodContext methodContext = context.asRequestMethodContext(method);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
} else if (methodConfig.isFlattening()) {
ClientMethodType clientMethodType;
if (methodConfig.isPageStreaming()) {
clientMethodType = ClientMethodType.PagedFlattenedMethod;
} else if (methodConfig.isLongRunningOperation()) {
clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
} else {
clientMethodType = ClientMethodType.FlattenedMethod;
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
} else {
// TODO: Add support of non-flattening method
// Github issue: https://github.com/googleapis/toolkit/issues/393
System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
}
}
return testCaseViews;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class JavaSurfaceTransformer method generatePagedResponseWrappers.
private List<StaticLangPagedResponseView> generatePagedResponseWrappers(InterfaceContext context, GapicProductConfig productConfig, ReleaseLevel releaseLevel) {
addPagedResponseWrapperImports(context.getImportTypeTable());
ImmutableList.Builder<StaticLangPagedResponseView> pagedResponseWrappersList = ImmutableList.builder();
for (MethodModel method : context.getSupportedMethods()) {
if (context.getMethodConfig(method).isPageStreaming()) {
pagedResponseWrappersList.add(generatePagedResponseWrapper(context.asRequestMethodContext(method), context.getImportTypeTable()));
}
}
return pagedResponseWrappersList.build();
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(InitCodeOutputType.SingleObject).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, getMethodType(methodContext.getMethodConfig())));
}
return testCaseViews;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceTransformer method createLongRunningDescriptors.
private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
List<LongRunningOperationDetailView> result = new ArrayList<>();
for (MethodModel method : context.getLongRunningMethods()) {
GapicMethodContext methodContext = context.asDynamicMethodContext(method);
LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig();
TypeModel returnType = lroConfig.getReturnType();
TypeModel metadataType = lroConfig.getMetadataType();
result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).implementsCancel(true).implementsDelete(true).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
}
return result;
}
Aggregations