use of com.google.api.codegen.viewmodel.StaticLangClientExampleFileView in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateExample.
private StaticLangClientExampleFileView generateExample(InterfaceContext context) {
StaticLangClientExampleFileView.Builder view = StaticLangClientExampleFileView.newBuilder();
SurfaceNamer namer = context.getNamer();
InterfaceModel apiInterface = context.getInterfaceModel();
ProductConfig productConfig = context.getProductConfig();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
view.templateFileName(SAMPLE_TEMPLATE_FILENAME);
String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
String fileName = namer.getExampleFileName(context.getInterfaceConfig());
view.outputPath(outputPath + File.separator + fileName);
view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
view.clientConstructorExampleName(namer.getApiWrapperClassConstructorExampleName(interfaceConfig));
view.apiMethods(generateApiMethods(context, context.getPublicMethods()));
view.iamResources(iamResourceTransformer.generateIamResources(context));
// Examples are different from the API. In particular, we use short declaration
// and so we omit most type names. We only need
// - Context, to initialize the client
// - The VKit generated library, that's what the sample is for
// - The input types of the methods, to initialize the requests
// So, we clear all imports; addXExampleImports will add back the ones we want.
context.getImportTypeTable().getImports().clear();
addXExampleImports(context, context.getPublicMethods());
view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return view.build();
}
Aggregations