Search in sources :

Example 21 with GapicInterfaceContext

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

the class RubyImportSectionTransformer method generateImportSection.

@Override
public ImportSectionView generateImportSection(TransformationContext transformationContext, String className) {
    // TODO support non-Gapic inputs
    GapicInterfaceContext context = (GapicInterfaceContext) transformationContext;
    Set<String> importFilenames = generateImportFilenames(context);
    ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
    importSection.standardImports(generateStandardImports());
    importSection.externalImports(generateExternalImports(context));
    importSection.appImports(generateAppImports(context, importFilenames));
    importSection.serviceImports(generateServiceImports(context, importFilenames));
    return importSection.build();
}
Also used : GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 22 with GapicInterfaceContext

use of com.google.api.codegen.config.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);
    Collection<InterfaceModel> interfaceModels = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).collect(ImmutableList.toImmutableList());
    List<GapicInterfaceContext> contexts = interfaceModels.stream().map(i -> createContext(i, productConfig)).collect(ImmutableList.toImmutableList());
    boolean hasSmokeTests = contexts.stream().map(InterfaceContext::getInterfaceConfig).map(InterfaceConfig::getSmokeTestConfig).anyMatch(Objects::nonNull);
    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)).jsonKeyVariable(namer.getJsonKeyVariable(false)).build();
}
Also used : PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) HashSet(java.util.HashSet) InterfaceContext(com.google.api.codegen.config.InterfaceContext) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) TargetLanguage(com.google.api.codegen.common.TargetLanguage) ValueProducer(com.google.api.codegen.util.testing.ValueProducer) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView) ImmutableSet(com.google.common.collect.ImmutableSet) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TocContentView(com.google.api.codegen.viewmodel.metadata.TocContentView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StandardValueProducer(com.google.api.codegen.util.testing.StandardValueProducer) Collection(java.util.Collection) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) DynamicLangApiMethodTransformer(com.google.api.codegen.transformer.DynamicLangApiMethodTransformer) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) List(java.util.List) ApiModel(com.google.api.codegen.config.ApiModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ReadmeMetadataView(com.google.api.codegen.viewmodel.metadata.ReadmeMetadataView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) Objects(java.util.Objects) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 23 with GapicInterfaceContext

use of com.google.api.codegen.config.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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 24 with GapicInterfaceContext

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

the class NodeJSGapicSurfaceTestTransformer method generateTestView.

private MockCombinedView generateTestView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ModelTypeTable typeTable = createTypeTable(productConfig);
    List<MockServiceImplView> impls = new ArrayList<>();
    List<ClientTestClassView> testClasses = new ArrayList<>();
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
        impls.add(MockServiceImplView.newBuilder().mockGrpcClassName(namer.getGrpcServerTypeName(context.getInterfaceModel())).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
    }
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        // We don't need any imports here.
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig), namer, featureConfig);
        testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - name")).testCases(createTestCaseViews(context)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.<MockServiceUsageView>emptyList()).build());
    }
    ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports(), null);
    return MockCombinedView.newBuilder().outputPath(testCaseOutputFile(namer)).serviceImpls(impls).mockServices(new ArrayList<MockServiceUsageView>()).testClasses(testClasses).localPackageName(namer.getLocalPackageName()).templateFileName(TEST_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).build();
}
Also used : MockServiceImplView(com.google.api.codegen.viewmodel.testing.MockServiceImplView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ArrayList(java.util.ArrayList) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 25 with GapicInterfaceContext

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

the class NodeJSGapicSurfaceTestTransformer method createSmokeTestViews.

private List<ViewModel> createSmokeTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        views.add(createSmokeTestClassView(context, model.hasMultipleServices()));
    }
    return views.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)28 ViewModel (com.google.api.codegen.viewmodel.ViewModel)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)15 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)15 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)9 MethodModel (com.google.api.codegen.config.MethodModel)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 HashSet (java.util.HashSet)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ApiModel (com.google.api.codegen.config.ApiModel)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