Search in sources :

Example 1 with ImportSectionView

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

Example 2 with ImportSectionView

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();
}
Also used : OutputView(com.google.api.codegen.viewmodel.OutputView) CallingForm(com.google.api.codegen.viewmodel.CallingForm) SampleValueSet(com.google.api.codegen.SampleValueSet) OutputContext(com.google.api.codegen.config.OutputContext) SampleFunctionDocView(com.google.api.codegen.viewmodel.SampleFunctionDocView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView) OutputSpec(com.google.api.codegen.OutputSpec) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 3 with ImportSectionView

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

Example 4 with ImportSectionView

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();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 5 with ImportSectionView

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