Search in sources :

Example 1 with ProductConfig

use of com.google.api.codegen.config.ProductConfig 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();
}
Also used : GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangClientExampleFileView(com.google.api.codegen.viewmodel.StaticLangClientExampleFileView) ProductConfig(com.google.api.codegen.config.ProductConfig) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 ProductConfig (com.google.api.codegen.config.ProductConfig)1 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 StaticLangClientExampleFileView (com.google.api.codegen.viewmodel.StaticLangClientExampleFileView)1