Search in sources :

Example 21 with ViewModel

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

the class JavaSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
    List<ViewModel> views = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty(), enableStringFormatFunctions);
            views.add(createSmokeTestClassView(context));
        }
    }
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        views.add(createMockServiceImplFileView(context));
        context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty(), enableStringFormatFunctions);
        views.add(createMockServiceView(context));
    }
    return views;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 22 with ViewModel

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

the class NodeJSGapicSurfaceTransformer method generateApiClasses.

private List<ViewModel> generateApiClasses(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
    Iterable<? extends InterfaceModel> interfaces = model.getInterfaces();
    for (InterfaceModel apiInterface : interfaces) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        models.add(generateApiClass(context, model.hasMultipleServices()));
    }
    return models.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 23 with ViewModel

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

the class PhpGapicSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> views = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.UNIT);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.SYSTEM);
            views.add(createSmokeTestClassView(context));
        }
    }
    return views;
}
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)

Example 24 with ViewModel

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

the class DiscoConfigGeneratorApi method generateConfig.

private Map<String, Doc> generateConfig(String outputPath) {
    Document document = setupDocument();
    ViewModel viewModel = new DiscoConfigTransformer().generateConfig(new DiscoApiModel(document, ""), outputPath);
    Doc generatedConfig = new CommonSnippetSetRunner(new CommonRenderingUtil()).generate(viewModel);
    return ImmutableMap.of(outputPath, generatedConfig);
}
Also used : DiscoApiModel(com.google.api.codegen.config.DiscoApiModel) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DiscoConfigTransformer(com.google.api.codegen.configgen.transformer.DiscoConfigTransformer) Document(com.google.api.codegen.discovery.Document)

Example 25 with ViewModel

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

the class DiscoGapicProvider method generate.

public Map<String, Doc> generate(String snippetFileName) {
    Map<String, Doc> docs = new LinkedTreeMap<>();
    for (DocumentToViewTransformer transformer : transformers) {
        List<ViewModel> surfaceDocs = transformer.transform(model, productConfig);
        for (ViewModel surfaceDoc : surfaceDocs) {
            if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
                continue;
            }
            Doc doc = snippetSetRunner.generate(surfaceDoc);
            if (doc == null) {
                // generation failed; failures are captured in the model.
                continue;
            }
            docs.put(surfaceDoc.outputPath(), doc);
        }
    }
    return docs;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DocumentToViewTransformer(com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)

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