Search in sources :

Example 1 with ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel 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 ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.

the class JavaGrpcMetadataProvider method generate.

@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) {
    ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<>();
    ProtoApiModel apiModel = new ProtoApiModel(model);
    ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
    metadataViews.addAll(transformer.transform(apiModel, config));
    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view);
        Doc result = runner.generate(view);
        if (!result.isWhitespace()) {
            docs.put(view.outputPath(), result);
        }
    }
    return docs.build();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) ArrayList(java.util.ArrayList) Doc(com.google.api.tools.framework.snippet.Doc) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel 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 4 with ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
    // TODO(andrealin): Remove the ProtoApiModel cast.
    Model model = ((ProtoApiModel) apiModel).getProtoModel();
    ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
    views.addAll(generateServiceSurfaces(model, productConfig));
    views.addAll(generateVersionedDirectoryViews(model, productConfig));
    views.addAll(generateTopLevelViews(model, productConfig));
    return views.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) FieldModel(com.google.api.codegen.config.FieldModel) MethodModel(com.google.api.codegen.config.MethodModel) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) Model(com.google.api.tools.framework.model.Model) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 5 with ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.

the class SampleManifestTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer surfaceNamer = newSurfaceNamer.apply(productConfig);
    ModelTypeTable typeTable = newTypeTable.apply(productConfig.getPackageName());
    FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
    ImmutableList.Builder<SampleManifestView.SampleEntry> builder = ImmutableList.builder();
    List<InterfaceContext> interfaceContexts = Streams.stream(model.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, surfaceNamer, featureConfig)).collect(ImmutableList.toImmutableList());
    List<SampleContext> sampleContexts = metadataNamer.getSampleContexts(interfaceContexts, productConfig);
    for (SampleContext context : sampleContexts) {
        String sample = context.uniqueSampleId();
        String path = metadataNamer.getSamplePath(sample);
        String regionTag = context.sampleConfig().regionTag();
        String className = metadataNamer.getSampleClassName(sample);
        builder.add(SampleManifestView.SampleEntry.create(sample, path, className, regionTag));
    }
    ImmutableList<SampleManifestView.SampleEntry> entries = builder.build();
    // Only generate manifest files when samples are configured through sample config.
    if (entries.isEmpty()) {
        return Collections.emptyList();
    }
    SampleManifestView.Builder sampleManifestView = SampleManifestView.newBuilder();
    sampleManifestView.environment(metadataNamer.getEnvironment());
    sampleManifestView.bin(metadataNamer.getBin());
    sampleManifestView.basePath(metadataNamer.getBasePath(productConfig));
    sampleManifestView.packageName(metadataNamer.getPackageName(productConfig));
    sampleManifestView.invocation(metadataNamer.getInvocation());
    sampleManifestView.schemaVersion(MANIFEST_SCHEMA_VERSION);
    sampleManifestView.sampleEntries(entries);
    sampleManifestView.outputPath(getManifestOutputPath(model, productConfig));
    sampleManifestView.templateFileName(TEMPLATE_NAME);
    return Collections.singletonList(sampleManifestView.build());
}
Also used : GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) SampleContext(com.google.api.codegen.config.SampleContext) Streams(com.google.common.collect.Streams) Function(java.util.function.Function) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) InterfaceContext(com.google.api.codegen.config.InterfaceContext) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionMatcher(com.google.api.codegen.util.VersionMatcher) Splitter(com.google.common.base.Splitter) Collections(java.util.Collections) ImmutableList(com.google.common.collect.ImmutableList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) SampleContext(com.google.api.codegen.config.SampleContext)

Aggregations

ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)15 ViewModel (com.google.api.codegen.viewmodel.ViewModel)9 ImmutableList (com.google.common.collect.ImmutableList)6 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)5 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 GeneratedResult (com.google.api.codegen.common.GeneratedResult)3 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)3 ModelToViewTransformer (com.google.api.codegen.transformer.ModelToViewTransformer)3 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)3 Function (java.util.function.Function)3 SnippetSetRunner (com.google.api.codegen.SnippetSetRunner)2 TargetLanguage (com.google.api.codegen.common.TargetLanguage)2 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)2 InterfaceContext (com.google.api.codegen.config.InterfaceContext)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 MethodModel (com.google.api.codegen.config.MethodModel)2