Search in sources :

Example 26 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class RubyPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. In the future,
// the example methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
            FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
            GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
            exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
        }
    }
    return exampleMethods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 27 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class RubyPackageMetadataTransformer method generateMetadataView.

private ViewModel generateMetadataView(ApiModel model, GapicProductConfig productConfig, String template, RubyPackageMetadataNamer namer, String filePrefix) {
    String noLeadingRubyDir = template.startsWith(RUBY_PREFIX) ? template.substring(RUBY_PREFIX.length()) : template;
    if (!Strings.isNullOrEmpty(filePrefix)) {
        noLeadingRubyDir = filePrefix + noLeadingRubyDir;
    }
    int extensionIndex = noLeadingRubyDir.lastIndexOf(".");
    String outputPath = noLeadingRubyDir.substring(0, extensionIndex);
    boolean hasSmokeTests = false;
    List<InterfaceModel> interfaceModels = new LinkedList<>();
    List<GapicInterfaceContext> contexts = new LinkedList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        interfaceModels.add(context.getInterfaceModel());
        contexts.add(context);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            hasSmokeTests = true;
        }
    }
    SurfaceNamer surfaceNamer = new RubySurfaceNamer(productConfig.getPackageName());
    ImportSectionView importSection = importSectionTransformer.generateRakefileAcceptanceTaskImportSection(contexts);
    return metadataTransformer.generateMetadataView(namer, packageConfig, model, template, outputPath, TargetLanguage.RUBY).identifier(namer.getMetadataIdentifier()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, surfaceNamer)).hasSmokeTests(hasSmokeTests).versionPath(surfaceNamer.getVersionIndexFileImportName()).versionNamespace(validVersionNamespace(interfaceModels, surfaceNamer)).credentialsClassName(surfaceNamer.getFullyQualifiedCredentialsClassName()).smokeTestProjectVariable(namer.getProjectVariable(true)).smokeTestKeyfileVariable(namer.getKeyfileVariable(true)).smokeTestJsonKeyVariable(namer.getJsonKeyVariable(true)).projectVariable(namer.getProjectVariable(false)).keyfileVariable(namer.getKeyfileVariable(false)).jsonKeyVariable(namer.getJsonKeyVariable(false)).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) LinkedList(java.util.LinkedList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)27 InterfaceModel (com.google.api.codegen.config.InterfaceModel)24 ViewModel (com.google.api.codegen.viewmodel.ViewModel)16 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)12 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 MethodModel (com.google.api.codegen.config.MethodModel)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 HashSet (java.util.HashSet)2 TargetLanguage (com.google.api.codegen.TargetLanguage)1 ApiModel (com.google.api.codegen.config.ApiModel)1