use of com.google.api.codegen.transformer.SurfaceNamer 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.transformer.SurfaceNamer in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/system").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
SmokeTestClassView.Builder testClass = createSmokeTestClassViewBuilder(context);
testClass.name(name);
testClass.outputPath(namer.getSourceFilePath(outputPath, name));
return testClass.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer 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;
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.
private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
List<RestInterfaceConfigView> configViews = new ArrayList<>();
GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
SurfaceNamer namer = context.getNamer();
Map<String, List<HttpRule>> interfaces = new TreeMap<>();
Service serviceConfig = serviceModel.getServiceConfig();
for (MethodModel methodModel : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
MethodConfig methodConfig = methodContext.getMethodConfig();
Method method = methodContext.getMethod();
// REST does not support streaming methods
if (methodConfig.isGrpcStreaming()) {
continue;
}
String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
String selector = httpRule.getSelector();
String interfaceName = selector.substring(0, selector.lastIndexOf("."));
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
}
return configViews;
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method buildGapicClientViewModel.
private ViewModel buildGapicClientViewModel(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
addApiImports(context);
List<ApiMethodView> methods = generateApiMethods(context);
DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder();
apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME);
apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName());
String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig());
apiImplClass.name(implName);
ProductServiceConfig productServiceConfig = new ProductServiceConfig();
apiImplClass.serviceAddress(productServiceConfig.getServiceAddress(context.getInterface().getModel()));
apiImplClass.servicePort(productServiceConfig.getServicePort());
apiImplClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel()));
apiImplClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel()));
apiImplClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
apiImplClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
apiImplClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
apiImplClass.pathTemplateGetterFunctions(pathTemplateTransformer.generatePathTemplateGetterFunctions(context));
apiImplClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
apiImplClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
apiImplClass.batchingDescriptors(ImmutableList.<BatchingDescriptorView>of());
apiImplClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
apiImplClass.longRunningDescriptors(createLongRunningDescriptors(context));
apiImplClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
apiImplClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));
apiImplClass.methodKeys(generateMethodKeys(context));
apiImplClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
apiImplClass.clientConfigName(namer.getClientConfigName(context.getInterfaceConfig()));
apiImplClass.interfaceKey(context.getInterface().getFullName());
String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel());
apiImplClass.grpcClientTypeName(grpcClientTypeName);
apiImplClass.apiMethods(methods);
apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
apiImplClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
// must be done as the last step to catch all imports
apiImplClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
apiImplClass.outputPath(outputPath + "/" + implName + ".php");
return apiImplClass.build();
}
Aggregations