use of com.google.api.codegen.viewmodel.ImportSectionView 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();
GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, 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(getApiName(context.getProductConfig().getPackageName()));
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.viewmodel.ImportSectionView in project toolkit by googleapis.
the class RubyImportSectionTransformer method generateRakefileAcceptanceTaskImportSection.
public ImportSectionView generateRakefileAcceptanceTaskImportSection(List<GapicInterfaceContext> contexts) {
List<ImportFileView> none = ImmutableList.of();
ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
importSection.standardImports(none);
importSection.externalImports(none);
Set<ImportFileView> credentialsImports = new HashSet<>();
for (GapicInterfaceContext context : contexts) {
credentialsImports.add(createImport(context.getNamer().getCredentialsClassImportName()));
}
importSection.appImports(ImmutableList.copyOf(credentialsImports));
importSection.serviceImports(none);
return importSection.build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateVersionedInitView.
private ViewModel generateVersionedInitView(Model model, GapicProductConfig productConfig) {
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
boolean packageHasEnums = packageHasEnums(model);
ImportSectionView imports = importSectionTransformer.generateVersionedInitImportSection(model, productConfig, namer, packageHasEnums);
return VersionIndexView.newBuilder().templateFileName(VERSIONED_INIT_TEMPLATE_FILENAME).outputPath(versionedInitOutputFile(namer)).requireViews(versionedInitRequireViews(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.
// entry point for generating standalone samples using sample config.
public MethodSampleView generateSample(MethodContext methodContext, SampleContext sampleContext) {
methodContext = methodContext.cloneWithEmptyTypeTable();
// request
InitCodeContext initCodeContext = createInitCodeContext(methodContext, sampleContext);
InitCodeView initCodeView = initCodeTransformer().generateInitCode(methodContext, initCodeContext);
// response
OutputContext outputContext = OutputContext.create();
List<ResponseStatementProto> outputs = sampleContext.sampleConfig().responseConfigs();
if (outputs.isEmpty()) {
outputs = OutputTransformer.defaultResponseStatements(methodContext);
}
ImmutableList<OutputView> outputViews = outputTransformer().toViews(outputs, methodContext, sampleContext, outputContext);
// imports
ImportSectionView sampleImportSectionView = sampleImportTransformer().generateImportSection(methodContext.cloneWithEmptyTypeTable(), sampleContext.callingForm(), outputContext, methodContext.getTypeTable(), initCodeTransformer().getInitCodeNodes(methodContext, // to avoid symbol collision
initCodeContext.cloneWithEmptySymbolTable()));
// Documentation
SampleFunctionDocView sampleFunctionDocView = SampleFunctionDocView.newBuilder().paramDocLines(paramDocLines(methodContext, initCodeView)).mainDocLines(ImmutableList.<String>builder().addAll(methodContext.getNamer().getWrappedDocLines(sampleContext.sampleConfig().description(), true)).build()).build();
// metadata
ImmutableList<String> metadataDescription = ImmutableList.<String>builder().addAll(methodContext.getNamer().getWrappedDocLines(sampleContext.sampleConfig().description(), false)).build();
String descriptionLine = metadataDescription.isEmpty() ? "" : metadataDescription.get(0);
ImmutableList<String> additionalDescriptionLines = metadataDescription.isEmpty() ? ImmutableList.of() : metadataDescription.subList(1, metadataDescription.size());
// assemble
return MethodSampleView.newBuilder().id(sampleContext.uniqueSampleId()).callingForm(sampleContext.callingForm()).sampleInitCode(initCodeView).outputs(outputViews).hasMultipleFileOutputs(outputContext.hasMultipleFileOutputs()).usesAsyncAwaitPattern(methodContext.getNamer().usesAsyncAwaitPattern(// Used by C# and Node.js
sampleContext.callingForm())).sampleImports(sampleImportSectionView).regionTag(sampleContext.sampleConfig().regionTag()).sampleFunctionName(methodContext.getNamer().getSampleFunctionName(methodContext.getMethodModel())).sampleFunctionDoc(sampleFunctionDocView).title(sampleContext.sampleConfig().title()).descriptionLine(descriptionLine).additionalDescriptionLines(additionalDescriptionLines).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class NodeJSGapicSurfaceTestTransformer method generateTestView.
private MockCombinedView generateTestView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
ModelTypeTable typeTable = createTypeTable(productConfig);
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(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
// We don't need any imports here.
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig), namer, featureConfig);
testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - name")).testCases(createTestCaseViews(context)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.<MockServiceUsageView>emptyList()).build());
}
ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports(), null);
return MockCombinedView.newBuilder().outputPath(testCaseOutputFile(namer)).serviceImpls(impls).mockServices(new ArrayList<MockServiceUsageView>()).testClasses(testClasses).localPackageName(namer.getLocalPackageName()).templateFileName(TEST_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).build();
}
Aggregations