use of com.google.api.codegen.config.FlatteningConfig in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createSmokeTestClassViewBuilder.
/**
* Package-private
*
* <p>A helper method that creates a partially initialized builder that can be customized and
* build the smoke test class view later.
*/
SmokeTestClassView.Builder createSmokeTestClassViewBuilder(InterfaceContext context) {
addSmokeTestImports(context);
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
SurfaceNamer namer = context.getNamer();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
// Imports must be done as the last step to catch all imports.
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testClass.fileHeader(fileHeader);
return testClass;
}
use of com.google.api.codegen.config.FlatteningConfig in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateApiMethods.
private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isPageStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
} else if (methodConfig.isGrpcStreaming()) {
ImportTypeTable typeTable = context.getImportTypeTable();
switch(methodConfig.getGrpcStreamingType()) {
case BidiStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
break;
case ClientStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
break;
case ServerStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
break;
default:
throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
}
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else if (methodConfig.isLongRunningOperation()) {
context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.FlatteningConfig in project toolkit by googleapis.
the class NodeJSGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext, packageHasMultipleServices);
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(name);
testClass.outputPath(namer.getSourceFilePath(SMOKE_TEST_OUTPUT_BASE_PATH, name));
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testClass.fileHeader(fileHeader);
return testClass.build();
}
use of com.google.api.codegen.config.FlatteningConfig in project toolkit by googleapis.
the class NodeJSPackageMetadataTransformer method generateExampleMethods.
// Generates methods used as examples for the README.md file.
// Note: This is based on sample gen method calls. In the future, the example
// methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = createContext(apiInterface, productConfig);
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
}
}
return exampleMethods.build();
}
use of com.google.api.codegen.config.FlatteningConfig in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method createSmokeTestClassViewBuilder.
private SmokeTestClassView.Builder createSmokeTestClassViewBuilder(GapicInterfaceContext context) {
addSmokeTestImports(context.getImportTypeTable());
SurfaceNamer namer = context.getNamer();
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
OptionalArrayMethodView apiMethod = createSmokeTestCaseApiMethodView(flattenedMethodContext);
testClass.apiSettingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()));
testClass.apiName(PhpPackageMetadataNamer.getApiNameFromPackageName(context.getNamer().getPackageName()).toLowerUnderscore());
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethod);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethod.initCode(), context.getNamer()));
testClass.methodName(namer.getTestCaseName(new SymbolTable(), method));
ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.SYSTEM));
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
testClass.fileHeader(fileHeader);
return testClass;
}
Aggregations