Search in sources :

Example 6 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class NodeJSPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// Note: This is based on sample gen method calls. In the future, the example
// methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
            FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
            GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
            exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
        }
    }
    return exampleMethods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 7 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method transform.

public List<ViewModel> transform(GapicInterfaceContext context) {
    GapicInterfaceContext gapicImplContext = context.withNewTypeTable(context.getNamer().getGapicImplNamespace());
    List<ViewModel> surfaceData = new ArrayList<>();
    surfaceData.add(buildGapicClientViewModel(gapicImplContext));
    surfaceData.add(buildClientViewModel(context));
    surfaceData.add(buildDescriptorConfigViewModel(context));
    surfaceData.add(buildRestConfigViewModel(context));
    return surfaceData;
}
Also used : ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 8 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext 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;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable)

Example 9 with GapicInterfaceContext

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

Example 10 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext 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();
}
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.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)27 InterfaceModel (com.google.api.codegen.config.InterfaceModel)24 ViewModel (com.google.api.codegen.viewmodel.ViewModel)16 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)12 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 MethodModel (com.google.api.codegen.config.MethodModel)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 HashSet (java.util.HashSet)2 TargetLanguage (com.google.api.codegen.TargetLanguage)1 ApiModel (com.google.api.codegen.config.ApiModel)1