Search in sources :

Example 6 with GapicInterfaceContext

use of com.google.api.codegen.config.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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
        models.add(createSmokeTestClassView(context, testPackageNamer));
    }
    return models.build();
}
Also used : GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) 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.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 7 with GapicInterfaceContext

use of com.google.api.codegen.config.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(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 8 with GapicInterfaceContext

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

the class PhpGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        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(productConfig));
        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.config.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.config.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.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 10 with GapicInterfaceContext

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

the class RubyGapicSurfaceTransformer method generateVersionIndexView.

private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    Iterable<? extends InterfaceModel> interfaces = model.getInterfaces(productConfig);
    for (InterfaceModel apiInterface : interfaces) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    // append any additional types
    Set<String> requireTypes = new HashSet<>();
    for (TypeModel type : model.getAdditionalTypes()) {
        if (type instanceof ProtoTypeRef) {
            ProtoTypeRef t = (ProtoTypeRef) type;
            String name = namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
            requireTypes.add(name);
        }
    }
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeModel(com.google.api.codegen.config.TypeModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) HashSet(java.util.HashSet)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)28 ViewModel (com.google.api.codegen.viewmodel.ViewModel)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)15 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)15 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)9 MethodModel (com.google.api.codegen.config.MethodModel)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 HashSet (java.util.HashSet)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodContext (com.google.api.codegen.config.MethodContext)2 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2