Search in sources :

Example 6 with MethodSampleView

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

the class StaticLangGapicSamplesTransformer method generateSamplesFromSampleConfigs.

private List<ViewModel> generateSamplesFromSampleConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig) {
    SurfaceNamer namer = newSurfaceNamer.apply(productConfig);
    List<SampleContext> sampleContexts = getSampleContexts(interfaceContexts, productConfig);
    List<ViewModel> sampleFileViews = new ArrayList<>();
    for (SampleContext sampleContext : sampleContexts) {
        StaticLangApiMethodView methodView = apiMethodTransformer.generateApiMethod(sampleContext.methodContext(), sampleContext);
        MethodSampleView methodSampleView = methodView.samples().get(0);
        String fileName = namer.getApiSampleFileName(sampleContext.uniqueSampleId());
        String className = namer.getApiSampleClassName(sampleContext.uniqueSampleId());
        InterfaceContext interfaceContext = sampleContext.methodContext().getSurfaceInterfaceContext();
        sampleFileViews.add(newSampleFileView(productConfig, interfaceContext, className, fileName, methodView, methodSampleView));
    }
    return sampleFileViews;
}
Also used : MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) SampleContext(com.google.api.codegen.config.SampleContext) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext)

Example 7 with MethodSampleView

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

the class StaticLangApiMethodTransformer method setFlattenedMethodFields.

private void setFlattenedMethodFields(MethodContext context, List<ParamWithSimpleDoc> additionalParams, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder, List<CallingForm> callingForms, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    Collection<FieldConfig> fieldConfigs = context.getFlatteningConfig().getFlattenedFieldConfigs().values();
    if (sampleContext == null) {
        sampleTransformer.generateSamples(methodViewBuilder, context, fieldConfigs, InitCodeOutputType.FieldList, callingForms);
    } else {
        MethodSampleView sampleView = sampleTransformer.generateSample(context, sampleContext);
        methodViewBuilder.samples(ImmutableList.of(sampleView));
    }
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(getMethodParamDocs(context, fieldConfigs, additionalParams)).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, synchronicity)).build());
    List<RequestObjectParamView> params = new ArrayList<>();
    for (FieldConfig fieldConfig : fieldConfigs) {
        params.add(resourceObjectTransformer.generateRequestObjectParam(context, fieldConfig));
    }
    methodViewBuilder.forwardingMethodParams(params);
    List<RequestObjectParamView> nonforwardingParams = new ArrayList<>(params);
    nonforwardingParams.addAll(ParamWithSimpleDoc.asRequestObjectParamViews(additionalParams));
    methodViewBuilder.methodParams(nonforwardingParams);
    methodViewBuilder.requestObjectParams(params);
    methodViewBuilder.pathTemplateChecks(generatePathTemplateChecks(context, fieldConfigs));
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 8 with MethodSampleView

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

the class DynamicLangGapicSamplesTransformer method generateSamplesFromSampleConfigs.

private List<ViewModel> generateSamplesFromSampleConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig) {
    SurfaceNamer namer = newSurfaceNamer.apply(productConfig);
    List<SampleContext> sampleContexts = getSampleContexts(interfaceContexts, productConfig);
    ImmutableList.Builder<ViewModel> sampleFileViews = ImmutableList.builder();
    for (SampleContext sampleContext : sampleContexts) {
        OptionalArrayMethodView methodView = apiMethodTransformer.generateApiMethod(sampleContext.methodContext(), sampleContext);
        MethodSampleView methodSampleView = methodView.samples().get(0);
        String fileName = namer.getApiSampleFileName(sampleContext.uniqueSampleId());
        InterfaceContext interfaceContext = sampleContext.methodContext().getSurfaceInterfaceContext();
        sampleFileViews.add(newSampleFileView(productConfig, interfaceContext, fileName, methodView, methodSampleView));
    }
    return sampleFileViews.build();
}
Also used : MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SampleContext(com.google.api.codegen.config.SampleContext) ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext)

Example 9 with MethodSampleView

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

the class DynamicLangGapicSamplesTransformer method generateSamplesFromGapicConfigs.

private List<ViewModel> generateSamplesFromGapicConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig, SurfaceNamer namer) {
    List<MethodSampleView> allSamples = interfaceContexts.stream().flatMap(c -> apiMethodTransformer.generateApiMethods(c).stream()).flatMap(m -> m.samples().stream()).collect(ImmutableList.toImmutableList());
    SampleFileRegistry registry = new SampleFileRegistry(namer, allSamples);
    ImmutableList.Builder<ViewModel> sampleFileViews = ImmutableList.builder();
    for (InterfaceContext context : interfaceContexts) {
        List<OptionalArrayMethodView> methods = apiMethodTransformer.generateApiMethods(context);
        for (OptionalArrayMethodView method : methods) {
            for (MethodSampleView sample : method.samples()) {
                sampleFileViews.add(newSampleFileView(productConfig, context, registry.getSampleFileName(sample, method.name()), method, sample));
            }
        }
    }
    return sampleFileViews.build();
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) ImmutableList(com.google.common.collect.ImmutableList) MethodContext(com.google.api.codegen.config.MethodContext) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) DynamicLangSampleView(com.google.api.codegen.viewmodel.DynamicLangSampleView) SampleConfig(com.google.api.codegen.config.SampleConfig) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SampleContext(com.google.api.codegen.config.SampleContext) CallingForm(com.google.api.codegen.viewmodel.CallingForm) Streams(com.google.common.collect.Streams) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) Paths(java.nio.file.Paths) SampleSpec(com.google.api.codegen.config.SampleSpec) ImmutableTable(com.google.common.collect.ImmutableTable) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext)

Aggregations

MethodSampleView (com.google.api.codegen.viewmodel.MethodSampleView)9 ArrayList (java.util.ArrayList)7 MethodModel (com.google.api.codegen.config.MethodModel)5 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)4 InterfaceContext (com.google.api.codegen.config.InterfaceContext)4 SampleContext (com.google.api.codegen.config.SampleContext)4 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)4 ViewModel (com.google.api.codegen.viewmodel.ViewModel)4 SampleConfig (com.google.api.codegen.config.SampleConfig)3 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)3 CallingForm (com.google.api.codegen.viewmodel.CallingForm)3 ImmutableList (com.google.common.collect.ImmutableList)3 FieldConfig (com.google.api.codegen.config.FieldConfig)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodContext (com.google.api.codegen.config.MethodContext)2 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2 SampleSpec (com.google.api.codegen.config.SampleSpec)2 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)2 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)2