Search in sources :

Example 6 with ViewModel

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

the class GoGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> models = new ArrayList<>();
    GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
        models.add(generate(context));
        context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
        models.add(generateExample(context));
    }
    models.add(generatePackageInfo(model, productConfig, namer));
    return models;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 7 with ViewModel

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

the class JavaSurfaceTransformer method transform.

public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    List<ServiceDocView> serviceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        StaticLangFileView<StaticLangApiView> apiFile = generateApiFile(context, productConfig);
        surfaceDocs.add(apiFile);
        serviceDocs.add(apiFile.classView().doc());
        StaticLangApiMethodView exampleApiMethod = getExampleApiMethod(apiFile.classView().apiMethods());
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubSettingsView> stubSettingsFile = generateStubSettingsFile(context, productConfig, exampleApiMethod);
        context = context.withNewTypeTable(namer.getRootPackageName());
        StaticLangFileView<StaticLangSettingsView> settingsFile = generateSettingsFile(context, productConfig, exampleApiMethod, stubSettingsFile.classView());
        surfaceDocs.add(settingsFile);
        surfaceDocs.add(stubSettingsFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubInterfaceView> stubInterfaceFile = generateStubInterfaceFile(context, productConfig);
        surfaceDocs.add(stubInterfaceFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangRpcStubView> grpcStubFile = generateRpcStubClassFile(context, productConfig);
        surfaceDocs.add(grpcStubFile);
        surfaceDocs.add(generateCallableFactoryClassFile(context, productConfig));
    }
    PackageInfoView packageInfo = generatePackageInfo(model, productConfig, namer, serviceDocs);
    surfaceDocs.add(packageInfo);
    return surfaceDocs;
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangStubInterfaceView(com.google.api.codegen.viewmodel.StaticLangStubInterfaceView) ArrayList(java.util.ArrayList) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 8 with ViewModel

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

the class NodeJSGapicSurfaceDocTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
    Model model = ((ProtoApiModel) apiModel).getProtoModel();
    ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
    for (ProtoFile file : new ProtoFileView().getElementIterable(model)) {
        surfaceDocs.add(generateDoc(file, productConfig));
    }
    return surfaceDocs.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoFileView(com.google.api.codegen.ProtoFileView) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Model(com.google.api.tools.framework.model.Model) ProtoFile(com.google.api.tools.framework.model.ProtoFile) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 9 with ViewModel

use of com.google.api.codegen.viewmodel.ViewModel 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 10 with ViewModel

use of com.google.api.codegen.viewmodel.ViewModel 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)

Aggregations

ViewModel (com.google.api.codegen.viewmodel.ViewModel)29 InterfaceModel (com.google.api.codegen.config.InterfaceModel)18 ArrayList (java.util.ArrayList)16 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)15 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 ImmutableList (com.google.common.collect.ImmutableList)9 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)6 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)4 Doc (com.google.api.tools.framework.snippet.Doc)4 SchemaTransformationContext (com.google.api.codegen.discogapic.SchemaTransformationContext)3 DiscoGapicInterfaceContext (com.google.api.codegen.transformer.DiscoGapicInterfaceContext)3 JavaSurfaceNamer (com.google.api.codegen.transformer.java.JavaSurfaceNamer)3 ProtoFileView (com.google.api.codegen.ProtoFileView)2 ApiModel (com.google.api.codegen.config.ApiModel)2 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)2 MethodModel (com.google.api.codegen.config.MethodModel)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2