Search in sources :

Example 1 with VersionIndexRequireView

use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.

the class NodeJSGapicSurfaceTransformer method generateIndexViews.

private List<ViewModel> generateIndexViews(Iterable<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
    NodeJSPackageMetadataNamer packageMetadataNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
    ArrayList<ViewModel> indexViews = new ArrayList<>();
    NodeJSSurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
    String version = namer.getApiWrapperModuleVersion();
    boolean hasVersion = version != null && !version.isEmpty();
    ArrayList<VersionIndexRequireView> requireViews = new ArrayList<>();
    for (InterfaceModel apiInterface : apiInterfaces) {
        Name serviceName = namer.getReducedServiceName(apiInterface.getSimpleName());
        String localName = hasVersion ? serviceName.join(version).toLowerCamel() : serviceName.toLowerCamel();
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        ApiMethodView exampleMethod = generateApiMethods(context, apiInterface.getApiModel().hasMultipleServices()).get(0);
        VersionIndexRequireView require = VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).localName(localName).doc(serviceTransformer.generateServiceDoc(context, exampleMethod, productConfig)).fileName(namer.getClientFileName(context.getInterfaceConfig())).build();
        requireViews.add(require);
    }
    String indexOutputPath = hasVersion ? "src/" + version + "/index.js" : "src/index.js";
    VersionIndexView.Builder indexViewbuilder = VersionIndexView.newBuilder().templateFileName(INDEX_TEMPLATE_FILE).outputPath(indexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier());
    if (hasVersion) {
        indexViewbuilder.apiVersion(version);
    }
    indexViews.add(indexViewbuilder.build());
    if (hasVersion) {
        String versionIndexOutputPath = "src/index.js";
        VersionIndexView.Builder versionIndexViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_INDEX_TEMPLATE_FILE).outputPath(versionIndexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).isGcloud(NodeJSUtils.isGcloud(productConfig)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
        indexViews.add(versionIndexViewBuilder.build());
    }
    return indexViews;
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ArrayList(java.util.ArrayList) VersionIndexView(com.google.api.codegen.viewmodel.metadata.VersionIndexView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) Name(com.google.api.codegen.util.Name) InterfaceModel(com.google.api.codegen.config.InterfaceModel)

Example 2 with VersionIndexRequireView

use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method versionedInitRequireViews.

private List<VersionIndexRequireView> versionedInitRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
    Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
    for (Interface apiInterface : apiInterfaces) {
        views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
    }
    return views.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Example 3 with VersionIndexRequireView

use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView 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();
    for (InterfaceModel apiInterface : interfaces) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        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.getVersionIndexFileImportName() + "/" + 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).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).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.transformer.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)

Example 4 with VersionIndexRequireView

use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method generateTypesView.

private ViewModel generateTypesView(Model model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    ImportSectionView imports = importSectionTransformer.generateTypesImportSection(model, productConfig);
    return VersionIndexView.newBuilder().templateFileName(TYPES_TEMPLEATE_FILENAME).outputPath(typesOutputFile(namer)).requireViews(ImmutableList.<VersionIndexRequireView>of()).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.PYTHON).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Example 5 with VersionIndexRequireView

use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method topLevelRequireViews.

private List<VersionIndexRequireView> topLevelRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
    Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
    for (Interface apiInterface : apiInterfaces) {
        views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
    }
    return views.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Aggregations

VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)6 ImmutableList (com.google.common.collect.ImmutableList)4 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)3 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 InterfaceView (com.google.api.codegen.InterfaceView)2 Interface (com.google.api.tools.framework.model.Interface)2 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 ProtoTypeRef (com.google.api.codegen.config.ProtoTypeRef)1 TypeModel (com.google.api.codegen.config.TypeModel)1 Name (com.google.api.codegen.util.Name)1 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)1 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 VersionIndexView (com.google.api.codegen.viewmodel.metadata.VersionIndexView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1