use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateTopLevelEntryPoint.
private ViewModel generateTopLevelEntryPoint(Model model, GapicProductConfig productConfig) {
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
boolean packageHasEnums = packageHasEnums(model);
ImportSectionView imports = importSectionTransformer.generateTopLeveEntryPointImportSection(model, productConfig, namer, packageHasEnums);
return VersionIndexView.newBuilder().templateFileName(TOP_LEVEL_ENTRY_POINT_FILENAME).outputPath(topLevelEntryPointFileName(namer)).requireViews(topLevelRequireViews(model, productConfig, namer)).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.PYTHON).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).packageHasEnums(packageHasEnums).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class SampleTransformer method generateSample.
private MethodSampleView generateSample(SampleConfig config, MethodContext methodContext, InitCodeContext initCodeContext) {
methodContext = methodContext.cloneWithEmptyTypeTable();
InitCodeView initCodeView = initCodeTransformer().generateInitCode(methodContext, initCodeContext);
SampleValueSet valueSet = config.valueSet();
CallingForm form = config.callingForm();
String regionTag = config.regionTag();
List<OutputSpec> outputs = valueSet.getOnSuccessList();
if (outputs.isEmpty()) {
outputs = OutputTransformer.defaultOutputSpecs(methodContext);
}
OutputContext outputContext = OutputContext.create();
ImmutableList<OutputView> outputViews = outputTransformer().toViews(outputs, methodContext, valueSet, form, outputContext);
ImportSectionView sampleImportSectionView = sampleImportTransformer().generateImportSection(methodContext.cloneWithEmptyTypeTable(), form, outputContext, methodContext.getTypeTable(), initCodeTransformer().getInitCodeNodes(methodContext, initCodeContext.cloneWithEmptySymbolTable()));
SampleFunctionDocView sampleFunctionDocView = SampleFunctionDocView.newBuilder().paramDocLines(paramDocLines(methodContext, initCodeView)).mainDocLines(ImmutableList.<String>builder().addAll(methodContext.getNamer().getWrappedDocLines(valueSet.getDescription(), true)).build()).build();
ImmutableList<String> metadataDescription = ImmutableList.<String>builder().addAll(methodContext.getNamer().getWrappedDocLines(valueSet.getDescription(), false)).build();
String descriptionLine = metadataDescription.isEmpty() ? "" : metadataDescription.get(0);
ImmutableList<String> additionalDescriptionLines = metadataDescription.isEmpty() ? ImmutableList.of() : metadataDescription.subList(1, metadataDescription.size());
return MethodSampleView.newBuilder().callingForm(form).id(valueSet.getId()).sampleInitCode(initCodeView).outputs(outputViews).hasMultipleFileOutputs(outputContext.hasMultipleFileOutputs()).usesAsyncAwaitPattern(// Used by C# and Node.js
methodContext.getNamer().usesAsyncAwaitPattern(form)).sampleImports(sampleImportSectionView).regionTag(regionTagFromSpec(regionTag, methodContext.getMethodModel().getSimpleName(), form, valueSet.getId())).sampleFunctionName(methodContext.getNamer().getSampleFunctionName(methodContext.getMethodModel())).sampleFunctionDoc(sampleFunctionDocView).title(config.valueSet().getTitle()).descriptionLine(descriptionLine).additionalDescriptionLines(additionalDescriptionLines).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, SurfaceNamer testPackageNamer) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
String version = packageConfig.apiVersion();
String filename = namer.classFileNameBase(Name.upperCamel(name).join(version)) + ".py";
String outputPath = Joiner.on(File.separator).join("tests", "system", "gapic", version, filename);
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
GapicMethodContext methodContext = context.asRequestMethodContext(method);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext);
boolean requireProjectId = testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer());
ImportSectionView importSection = importSectionTransformer.generateSmokeTestImportSection(context, requireProjectId);
return SmokeTestClassView.newBuilder().apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig())).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).apiVariableName(namer.getApiWrapperModuleName()).name(name).outputPath(outputPath).templateFileName(SMOKE_TEST_TEMPLATE_FILE).apiMethod(apiMethodView).requireProjectId(requireProjectId).fileHeader(fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer)).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView 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(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
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)).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.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateTopLevelEntryPoint.
private ViewModel generateTopLevelEntryPoint(ProtoApiModel apiModel, GapicProductConfig productConfig) {
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
boolean packageHasEnums = packageHasEnums(apiModel.getProtoModel());
ImportSectionView imports = importSectionTransformer.generateTopLeveEntryPointImportSection(apiModel, productConfig, namer, packageHasEnums);
return VersionIndexView.newBuilder().templateFileName(TOP_LEVEL_ENTRY_POINT_FILENAME).outputPath(topLevelEntryPointFileName(namer)).requireViews(topLevelRequireViews(apiModel, productConfig, namer)).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).packageHasEnums(packageHasEnums).build();
}
Aggregations