use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method buildClientViewModel.
private ViewModel buildClientViewModel(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
String name = namer.getApiWrapperClassName(context.getInterfaceConfig());
context.getImportTypeTable().getAndSaveNicknameFor(PhpPackageUtil.getFullyQualifiedName(namer.getGapicImplNamespace(), namer.getApiWrapperClassImplName(context.getInterfaceConfig())));
DynamicLangXApiSubclassView.Builder apiClass = DynamicLangXApiSubclassView.newBuilder();
apiClass.templateFileName(API_TEMPLATE_FILENAME);
apiClass.protoFilename(context.getInterface().getFile().getSimpleName());
apiClass.name(name);
apiClass.parentName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
apiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
apiClass.outputPath(outputPath + "/" + name + ".php");
return apiClass.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModelT model, GapicProductConfig productConfig) {
SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
List<ViewModel> views = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createUnitTestFileView(context));
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createSmokeTestClassView(context));
}
}
for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createMockServiceImplFileView(context));
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createMockServiceView(context));
}
return views;
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createUnitTestFileView.
// /////////////////////////////////// Unit Test /////////////////////////////////////////
private ClientTestFileView createUnitTestFileView(InterfaceContext context) {
addUnitTestImports(context);
String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
String name = namer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiStubSettingsClassName(namer.getApiStubSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(name);
testClass.testCases(createTestCaseViews(context));
testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
testClass.transportProtocol(context.getProductConfig().getTransportProtocol());
ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
testFile.testClass(testClass.build());
testFile.outputPath(namer.getSourceFilePath(outputPath, name));
testFile.templateFileName(unitTestTemplateFile);
// Imports must be done as the last step to catch all imports.
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testFile.fileHeader(fileHeader);
return testFile.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaDiscoGapicResourceNameToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel apiModel, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(apiModel, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.create(productConfig));
// Keep track of which name patterns have been generated to avoid duplicate classes.
Set<String> namePatterns = new HashSet<>();
for (String interfaceName : productConfig.getInterfaceConfigMap().keySet()) {
SchemaTransformationContext requestContext = SchemaTransformationContext.create(interfaceName, context.getSchemaTypeTable(), context);
// Maps a canonical resource name pattern to any method that uses that pattern.
Map<String, Method> namePatternsToMethod = new HashMap<>();
for (MethodConfig methodConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getMethodConfigs()) {
Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
namePatternsToMethod.put(DiscoGapicParser.getCanonicalPath(method.flatPath()), method);
}
for (SingleResourceNameConfig nameConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getSingleResourceNameConfigs()) {
String namePattern = nameConfig.getNamePattern();
if (namePatterns.contains(namePattern)) {
continue;
}
Method method = namePatternsToMethod.get(namePattern);
StaticLangApiResourceNameView resourceNameView = generateResourceNameClass(requestContext, method, nameConfig);
surfaceRequests.add(generateResourceNameFile(requestContext, resourceNameView));
namePatterns.add(nameConfig.getNamePattern());
}
}
Collections.sort(surfaceRequests, new Comparator<ViewModel>() {
@Override
public int compare(ViewModel o1, ViewModel o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
}
});
return surfaceRequests;
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaDiscoGapicRequestToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()));
for (DiscoveryMethodModel method : context.getSupportedMethods()) {
RequestObjectParamView params = getRequestObjectParams(context, method);
SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
surfaceRequests.add(generateRequestFile(requestContext, requestView));
}
}
surfaceRequests.sort((ViewModel o1, ViewModel o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath()));
return surfaceRequests;
}
Aggregations