use of com.google.api.codegen.transformer.ModelTypeTable in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable modelTypeTable = new ModelTypeTable(new PhpTypeTable(productConfig.getPackageName()), new PhpModelTypeNameConverter(productConfig.getPackageName()));
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, new PhpSurfaceNamer(productConfig.getPackageName()), new PhpFeatureConfig());
surfaceDocs.addAll(transform(context));
}
return surfaceDocs;
}
use of com.google.api.codegen.transformer.ModelTypeTable in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createSmokeTestViews.
private List<ViewModel> createSmokeTestViews(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
SurfaceNamer surfacePackageNamer = new PythonSurfaceNamer(productConfig.getPackageName());
SurfaceNamer testPackageNamer = new PythonSurfaceNamer(surfacePackageNamer.getTestPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
models.add(createSmokeTestClassView(context, testPackageNamer));
}
}
return models.build();
}
use of com.google.api.codegen.transformer.ModelTypeTable in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createUnitTestViews.
private List<ViewModel> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
SurfaceNamer surfacePackageNamer = new PythonSurfaceNamer(productConfig.getPackageName());
SurfaceNamer testPackageNamer = new PythonSurfaceNamer(surfacePackageNamer.getTestPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
String testClassName = surfacePackageNamer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView testClassView = ClientTestClassView.newBuilder().apiSettingsClassName(surfacePackageNamer.getNotImplementedString("PythonGapicSurfaceTestTransformer.createUnitTestViews - apiSettingsClassName")).apiClassName(surfacePackageNamer.getApiWrapperClassName(context.getInterfaceConfig())).apiVariableName(surfacePackageNamer.getApiWrapperModuleName()).name(testClassName).apiName(surfacePackageNamer.publicClassName(Name.upperCamelKeepUpperAcronyms(context.getInterfaceModel().getSimpleName()))).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).apiHasUnaryUnaryMethod(hasUnaryUnary(context.getInterfaceConfig())).apiHasUnaryStreamingMethod(hasUnaryStreaming(context.getInterfaceConfig())).apiHasStreamingUnaryMethod(hasStreamingUnary(context.getInterfaceConfig())).apiHasStreamingStreamingMethod(hasStreamingStreaming(context.getInterfaceConfig())).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
String version = packageConfig.apiVersion();
String filename = surfacePackageNamer.classFileNameBase(Name.upperCamel(testClassName).join(version)) + ".py";
String outputPath = Joiner.on(File.separator).join("tests", "unit", "gapic", version, filename);
ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
models.add(ClientTestFileView.newBuilder().templateFileName(TEST_TEMPLATE_FILE).outputPath(outputPath).testClass(testClassView).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, testPackageNamer)).build());
}
return models.build();
}
use of com.google.api.codegen.transformer.ModelTypeTable in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method addMethodImports.
private void addMethodImports(GapicMethodContext context) {
ModelTypeTable typeTable = context.getTypeTable();
GapicMethodConfig methodConfig = context.getMethodConfig();
if (methodConfig.isLongRunningOperation()) {
typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType());
typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType());
}
typeTable.getAndSaveNicknameFor(context.getMethod().getInputType());
addFieldsImports(typeTable, methodConfig.getRequiredFields());
addFieldsImports(typeTable, methodConfig.getOptionalFields());
}
use of com.google.api.codegen.transformer.ModelTypeTable in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method generateMockServiceView.
private MockCombinedView generateMockServiceView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
ModelTypeTable typeTable = GoGapicSurfaceTransformer.createTypeTable();
List<MockServiceImplView> impls = new ArrayList<>();
List<ClientTestClassView> testClasses = new ArrayList<>();
for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
impls.add(MockServiceImplView.newBuilder().mockGrpcClassName(namer.getGrpcServerTypeName(context.getInterfaceModel())).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
}
for (InterfaceModel apiInterface : model.getInterfaces()) {
// We don't need any import here.
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - name")).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.<MockServiceUsageView>emptyList()).build());
}
ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports());
return MockCombinedView.newBuilder().outputPath(productConfig.getPackageName() + File.separator + "mock_test.go").serviceImpls(impls).testClasses(testClasses).templateFileName(MOCK_SERVICE_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).mockServices(mockServiceTransformer.createMockServices(namer, model, productConfig)).build();
}
Aggregations