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;
}
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));
}
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();
}
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();
}
Aggregations