Search in sources :

Example 1 with ViewModel

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

the class ViewModelGapicProvider method generate.

@Override
public Map<String, Doc> generate(String snippetFileName) {
    // Establish required stage for generation.
    model.establishStage(Merged.KEY);
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    }
    List<ViewModel> surfaceDocs = modelToViewTransformer.transform(new ProtoApiModel(model), productConfig);
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    }
    Map<String, Doc> docs = new TreeMap<>();
    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 : ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TreeMap(java.util.TreeMap)

Example 2 with ViewModel

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

the class ViewModelDiscoGapicProvider method generate.

@Override
public Map<String, Doc> generate(String snippetFileName) {
    List<ViewModel> surfaceDocs = modelToViewTransformer.transform(model, productConfig);
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    }
    Map<String, Doc> docs = new TreeMap<>();
    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 : Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TreeMap(java.util.TreeMap)

Example 3 with ViewModel

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

the class CSharpGapicSmokeTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getPackageName()), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        SmokeTestClassView smokeTests = generateSmokeTest(context);
        if (smokeTests != null) {
            surfaceDocs.add(smokeTests);
            surfaceDocs.add(generateSmokeTestCsproj(context));
        }
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) 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 4 with ViewModel

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

the class CSharpGapicSnippetsTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getExamplePackageName()), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        context.getImportTypeTable().saveNicknameFor("Google.Protobuf.Bytestring");
        context.getImportTypeTable().saveNicknameFor("System.Linq.__import__");
        SnippetsFileView snippets = generateSnippets(context);
        surfaceDocs.add(snippets);
    }
    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) SnippetsFileView(com.google.api.codegen.viewmodel.SnippetsFileView)

Example 5 with ViewModel

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

the class CSharpGapicUnitTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getPackageName()), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        ModelTypeTable typeTable = context.getImportTypeTable();
        typeTable.saveNicknameFor("Xunit.FactAttribute");
        typeTable.saveNicknameFor("Moq.Mock");
        if (context.getLongRunningMethods().iterator().hasNext()) {
            typeTable.saveNicknameFor("Google.LongRunning.Operations");
        }
        surfaceDocs.add(generateUnitTest(context));
        surfaceDocs.add(generateUnitTestCsproj(context));
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) 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