Search in sources :

Example 6 with ImportSectionView

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;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SymbolTable(com.google.api.codegen.util.SymbolTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 7 with ImportSectionView

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();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) HashSet(java.util.HashSet)

Example 8 with ImportSectionView

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();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 9 with ImportSectionView

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();
}
Also used : ResponseStatementProto(com.google.api.codegen.samplegen.v1p2.ResponseStatementProto) OutputView(com.google.api.codegen.viewmodel.OutputView) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) OutputContext(com.google.api.codegen.config.OutputContext) SampleFunctionDocView(com.google.api.codegen.viewmodel.SampleFunctionDocView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 10 with ImportSectionView

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();
}
Also used : MockServiceImplView(com.google.api.codegen.viewmodel.testing.MockServiceImplView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ArrayList(java.util.ArrayList) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)9 InterfaceModel (com.google.api.codegen.config.InterfaceModel)8 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)5 ImmutableList (com.google.common.collect.ImmutableList)5 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)4 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)3 MethodModel (com.google.api.codegen.config.MethodModel)3 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 OutputContext (com.google.api.codegen.config.OutputContext)2 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)2 ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 ArrayList (java.util.ArrayList)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 TargetLanguage (com.google.api.codegen.common.TargetLanguage)1