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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations