Search in sources :

Example 71 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateCredentialsView.

private ViewModel generateCredentialsView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    CredentialsClassView credentialsClass = generateCredentialsClass(model, productConfig);
    ImportSectionView importSection = ImportSectionView.newBuilder().externalImports(ImmutableList.of(ImportFileView.newBuilder().moduleName("googleauth").types(ImmutableList.<ImportTypeView>of()).build())).build();
    List<String> modules = namer.getApiModules();
    InterfaceModel apiInterface = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).findFirst().orElseThrow(() -> new NoSuchElementException("reachable API interfaces"));
    GapicInterfaceContext context = createContext(apiInterface, productConfig);
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    return CredentialsClassFileView.newBuilder().outputPath(namer.getSourceFilePath(subPath, "Credentials")).templateFileName(CREDENTIALS_CLASS_TEMPLATE_FILE).credentialsClass(credentialsClass).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer, ImmutableList.copyOf(modules))).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) CredentialsClassView(com.google.api.codegen.viewmodel.CredentialsClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) NoSuchElementException(java.util.NoSuchElementException) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 72 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer 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 73 with SurfaceNamer

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

the class JavaSurfaceTestTransformer method createSmokeTestClassView.

// /////////////////////////////////// Smoke Test ///////////////////////////////////////
private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
    String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    SmokeTestClassView.Builder testClass = createSmokeTestClassViewBuilder(context);
    testClass.name(name);
    testClass.outputPath(namer.getSourceFilePath(outputPath, name));
    return testClass.build();
}
Also used : SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 74 with SurfaceNamer

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

the class NodeJSApiMethodParamTransformer method generateMethodParamDocs.

private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields, boolean isOptional) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
    for (FieldModel field : fields) {
        if (isRequestTokenParam(methodConfig, field)) {
            continue;
        }
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        String paramName = "request." + namer.getVariableName(field);
        if (isOptional) {
            paramName = String.format("[%s]", paramName);
        }
        paramDoc.paramName(paramName);
        String typeName = namer.getParamTypeName(context.getTypeTable(), field.getType());
        paramDoc.typeName(typeName);
        List<String> fieldDocLines = namer.getDocLines(field);
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (isPageSizeParam(methodConfig, field)) {
            docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
        } else {
            docLines.addAll(fieldDocLines);
        }
        paramDoc.lines(docLines.build());
        docs.add(paramDoc.build());
    }
    return docs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 75 with SurfaceNamer

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

the class PhpGapicSurfaceTestTransformer method createUnitTestFileView.

private ClientTestFileView createUnitTestFileView(GapicInterfaceContext context) {
    addUnitTestImports(context.getImportTypeTable());
    String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/Unit").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getNotImplementedString("PhpGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName"));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.apiName(getApiName(context.getProductConfig().getPackageName()));
    testClass.testCases(createTestCaseViews(context));
    // Add gRPC client imports.
    for (InterfaceModel grpcInterface : mockServiceTransformer.getGrpcInterfacesForService(context.getApiModel(), context.getProductConfig(), context.getInterfaceModel()).values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcClientTypeName(grpcInterface));
    }
    testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
    testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
    testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
    ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
    testFile.testClass(testClass.build());
    testFile.outputPath(namer.getSourceFilePath(outputPath, name));
    testFile.templateFileName(UNIT_TEST_TEMPLATE_FILE);
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.UNIT));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testFile.fileHeader(fileHeader);
    return testFile.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)109 InterfaceModel (com.google.api.codegen.config.InterfaceModel)26 ViewModel (com.google.api.codegen.viewmodel.ViewModel)23 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 ArrayList (java.util.ArrayList)22 ImmutableList (com.google.common.collect.ImmutableList)17 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)15 MethodModel (com.google.api.codegen.config.MethodModel)14 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)13 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)11 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)10 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ApiModel (com.google.api.codegen.config.ApiModel)9 MethodConfig (com.google.api.codegen.config.MethodConfig)9 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)9 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)9 FieldConfig (com.google.api.codegen.config.FieldConfig)8 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)8 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)8