Search in sources :

Example 26 with ViewModel

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

the class JavaDiscoGapicRequestToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
        DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()), enableStringFormatFunctions);
        for (MethodModel method : context.getSupportedMethods()) {
            RequestObjectParamView params = getRequestObjectParams(context, method);
            SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
            StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
            surfaceRequests.add(generateRequestFile(requestContext, requestView));
        }
    }
    Collections.sort(surfaceRequests, new Comparator<ViewModel>() {

        @Override
        public int compare(ViewModel o1, ViewModel o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
        }
    });
    return surfaceRequests;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) InterfaceModel(com.google.api.codegen.config.InterfaceModel) StaticLangApiMessageView(com.google.api.codegen.viewmodel.StaticLangApiMessageView) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.transformer.DiscoGapicInterfaceContext)

Example 27 with ViewModel

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

the class PythonGapicSurfaceTransformer method generateServiceSurfaces.

private Iterable<ViewModel> generateServiceSurfaces(Model model, GapicProductConfig productConfig) {
    ModelTypeTable modelTypeTable = new ModelTypeTable(new PythonTypeTable(productConfig.getPackageName()), new PythonModelTypeNameConverter(productConfig.getPackageName()));
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new DefaultFeatureConfig();
    ProtoApiModel apiModel = new ProtoApiModel(model);
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : apiModel.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        addApiImports(context);
        serviceSurfaces.add(generateApiClass(context));
    }
    GrpcDocView enumFile = generateEnumView(productConfig, modelTypeTable, namer, model.getFiles());
    if (!enumFile.elementDocs().isEmpty()) {
        serviceSurfaces.add(enumFile);
    }
    return serviceSurfaces.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfig(com.google.api.codegen.transformer.FeatureConfig) DefaultFeatureConfig(com.google.api.codegen.transformer.DefaultFeatureConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) PythonTypeTable(com.google.api.codegen.util.py.PythonTypeTable) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) DefaultFeatureConfig(com.google.api.codegen.transformer.DefaultFeatureConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 28 with ViewModel

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

the class PythonPackageMetadataTransformer method generateTopLevelFiles.

private List<ViewModel> generateTopLevelFiles(ApiModel model, GapicProductConfig productConfig) {
    PackageMetadataNamer namer = new PackageMetadataNamer();
    SurfaceNamer surfaceNamer = new PythonSurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<ViewModel> metadata = ImmutableList.builder();
    for (Map.Entry<String, String> entry : TOP_LEVEL_TEMPLATE_FILES.entrySet()) {
        metadata.add(generateMetadataView(model, productConfig, entry.getKey(), namer, surfaceNamer, entry.getValue()).build());
    }
    return metadata.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 29 with ViewModel

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

the class RubyGapicSurfaceTransformer method generateApiClasses.

private List<ViewModel> generateApiClasses(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new RubyFeatureConfig();
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        String packageName = productConfig.getPackageName();
        ModelTypeTable modelTypeTable = new ModelTypeTable(new RubyTypeTable(productConfig.getPackageName()), new RubyModelTypeNameConverter(packageName));
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        serviceSurfaces.add(generateApiClass(context, packageName));
    }
    return serviceSurfaces.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfig(com.google.api.codegen.transformer.FeatureConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

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