Search in sources :

Example 16 with ViewModel

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

the class RubyGapicSurfaceDocTransformer method transform.

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

Example 17 with ViewModel

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

the class JavaDiscoGapicResourceNameToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel apiModel, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(apiModel, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.newBuilder().enableStringFormatFunctions(true).build());
    // Keep track of which name patterns have been generated to avoid duplicate classes.
    Set<String> namePatterns = new HashSet<>();
    for (String interfaceName : productConfig.getInterfaceConfigMap().keySet()) {
        SchemaTransformationContext requestContext = SchemaTransformationContext.create(interfaceName, context.getSchemaTypeTable(), context);
        // Maps a canonical resource name pattern to any method that uses that pattern.
        Map<String, Method> namePatternsToMethod = new HashMap<>();
        for (MethodConfig methodConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getMethodConfigs()) {
            Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
            namePatternsToMethod.put(DiscoGapicParser.getCanonicalPath(method), method);
        }
        for (SingleResourceNameConfig nameConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getSingleResourceNameConfigs()) {
            String namePattern = nameConfig.getNamePattern();
            if (namePatterns.contains(namePattern)) {
                continue;
            }
            Method method = namePatternsToMethod.get(namePattern);
            StaticLangApiResourceNameView resourceNameView = generateResourceNameClass(requestContext, method, nameConfig);
            surfaceRequests.add(generateResourceNameFile(requestContext, resourceNameView));
            namePatterns.add(nameConfig.getNamePattern());
        }
    }
    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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Method(com.google.api.codegen.discovery.Method) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) StaticLangApiResourceNameView(com.google.api.codegen.viewmodel.StaticLangApiResourceNameView) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.transformer.DiscoGapicInterfaceContext) HashSet(java.util.HashSet)

Example 18 with ViewModel

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

the class JavaDiscoGapicSchemaToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceSchemas = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    JavaSurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(model, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.newBuilder().enableStringFormatFunctions(true).build());
    for (Schema schema : context.getDocument().schemas().values()) {
        Map<SchemaTransformationContext, StaticLangApiMessageView> contextViews = new TreeMap<>(SchemaTransformationContext.comparator);
        generateSchemaClasses(contextViews, context, schema);
        for (Map.Entry<SchemaTransformationContext, StaticLangApiMessageView> contextView : contextViews.entrySet()) {
            surfaceSchemas.add(generateSchemaFile(contextView.getKey(), contextView.getValue()));
        }
    }
    Collections.sort(surfaceSchemas, new Comparator<ViewModel>() {

        @Override
        public int compare(ViewModel o1, ViewModel o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
        }
    });
    return surfaceSchemas;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) Schema(com.google.api.codegen.discovery.Schema) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TreeMap(java.util.TreeMap) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) StaticLangApiMessageView(com.google.api.codegen.viewmodel.StaticLangApiMessageView) Map(java.util.Map) TreeMap(java.util.TreeMap) DiscoGapicInterfaceContext(com.google.api.codegen.transformer.DiscoGapicInterfaceContext)

Example 19 with ViewModel

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

the class CSharpGapicClientTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
    InterfaceModel lastApiInterface = null;
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
        surfaceDocs.add(generateApiAndSettingsView(context));
        lastApiInterface = apiInterface;
    }
    GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
    surfaceDocs.add(generateResourceNamesView(context));
    surfaceDocs.add(generateCsProjView(context));
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 20 with ViewModel

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

the class GoGapicSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
    List<ViewModel> models = new ArrayList<ViewModel>();
    models.add(generateMockServiceView(model, productConfig, namer));
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, GoGapicSurfaceTransformer.createTypeTable(), namer, featureConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            models.add(createSmokeTestClassView(context));
        }
    }
    return models;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) 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