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<OptionalArrayMethodView> methods = apiMethodTransformer.generateApiMethods(context);
DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder();
apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME);
apiImplClass.supportsGrpcTransport(supportsGrpcTransport());
apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName());
String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig());
apiImplClass.name(implName);
String serviceAddress = context.getServiceAddress();
apiImplClass.serviceHostname(productServiceConfig.getServiceHostname(serviceAddress));
apiImplClass.servicePort(productServiceConfig.getServicePort(serviceAddress));
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.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
apiImplClass.clientConfigName(namer.getClientConfigName(context.getInterfaceConfig()));
apiImplClass.interfaceKey(context.getInterface().getFullName());
if (supportsGrpcTransport()) {
// PHP generates a client that supports both gRPC and REST
String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel());
apiImplClass.grpcClientTypeName(grpcClientTypeName);
apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
} else {
// PHP generates a client that only supports REST
apiImplClass.grpcClientTypeName("");
apiImplClass.stubs(Collections.emptyList());
}
apiImplClass.apiMethods(methods.stream().collect(Collectors.toList()));
apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
// 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();
}
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.asRequestMethodContext(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 RubyApiMethodParamTransformer method generateMethodParamDocs.
private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
SurfaceNamer namer = context.getNamer();
MethodConfig methodConfig = context.getMethodConfig();
ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
for (FieldModel field : fields) {
if (isRequestTokenParam(methodConfig, field)) {
continue;
}
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
paramDoc.paramName(namer.getVariableName(field));
paramDoc.typeName(namer.getParamTypeName(context.getTypeTable(), field.getType()));
ImmutableList.Builder<String> docLines = ImmutableList.builder();
if (isPageSizeParam(methodConfig, field)) {
docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
} else {
docLines.addAll(namer.getDocLines(field));
boolean isMessageField = field.isMessage() && !field.isMap();
boolean isMapContainingMessage = field.isMap() && field.getType().getMapValueType().isMessage();
if (isMessageField || isMapContainingMessage) {
String messageType;
if (isMapContainingMessage) {
messageType = context.getTypeTable().getFullNameForElementType(field.getType().getMapValueType());
} else {
messageType = context.getTypeTable().getFullNameForElementType(field);
}
docLines.add(String.format("A hash of the same form as `%s`", messageType));
docLines.add("can also be provided.");
}
}
paramDoc.lines(docLines.build());
docs.add(paramDoc.build());
}
return docs.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
boolean packageHasMultipleServices = context.getApiModel().hasMultipleServices();
String outputPath = smokeTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
RubyPackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(context.getNamer().getPackageName());
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
MethodContext methodContext = context.asRequestMethodContext(method);
TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(methodContext.getMethodConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, 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(outputPath, name));
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
testClass.projectIdVariableName(metadataNamer.getProjectVariable(true));
testClass.apiVersion(packageConfig.apiVersion());
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSectionTransformer.generateSmokeTestImportSection(context), namer);
testClass.fileHeader(fileHeader);
return testClass.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createUnitTestClassView.
private ClientTestClassView createUnitTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
SurfaceNamer namer = context.getNamer();
String apiSettingsClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - apiSettingsClassName");
String testClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - name");
ImmutableList.Builder<ClientInitParamView> clientInitOptionalParams = ImmutableList.builder();
if (RubyUtil.hasMajorVersion(context.getProductConfig().getPackageName())) {
clientInitOptionalParams.add(ClientInitParamView.newBuilder().key("version").value(":" + packageConfig.apiVersion()).build());
}
return ClientTestClassView.newBuilder().apiSettingsClassName(apiSettingsClassName).apiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig())).name(testClassName).testCases(createUnitTestCaseViews(context, packageHasMultipleServices)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockCredentialsClassName(namer.getMockCredentialsClassName(context.getInterface())).fullyQualifiedCredentialsClassName(namer.getFullyQualifiedCredentialsClassName()).clientInitOptionalParams(clientInitOptionalParams.build()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
}
Aggregations