use of com.google.api.codegen.config.ProtoTypeRef in project toolkit by googleapis.
the class RubyGapicSurfaceTransformer method generateVersionIndexView.
private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
Iterable<? extends InterfaceModel> interfaces = model.getInterfaces(productConfig);
for (InterfaceModel apiInterface : interfaces) {
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
if (interfaceConfig == null) {
continue;
}
GapicInterfaceContext context = createContext(apiInterface, productConfig);
requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
}
// append any additional types
Set<String> requireTypes = new HashSet<>();
for (TypeModel type : model.getAdditionalTypes()) {
if (type instanceof ProtoTypeRef) {
ProtoTypeRef t = (ProtoTypeRef) type;
String name = namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
requireTypes.add(name);
}
}
return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).build();
}
use of com.google.api.codegen.config.ProtoTypeRef in project toolkit by googleapis.
the class NodeJSSurfaceNamer method returnTypeDoc.
private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
String returnTypeDoc = "";
if (methodConfig.isPageStreaming()) {
returnTypeDoc = "Array of ";
FieldModel resourcesType = methodConfig.getPageStreaming().getResourcesField();
if (resourcesType.isMessage()) {
returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType());
} else if (resourcesType.isEnum()) {
returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType());
} else {
// Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter.
returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase();
}
} else if (methodConfig.isLongRunningOperation()) {
returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object";
} else {
returnTypeDoc = getTypeNameDoc(typeTable, new ProtoTypeRef(methodConfig.getMethod().getOutputType()));
}
return returnTypeDoc;
}
use of com.google.api.codegen.config.ProtoTypeRef in project toolkit by googleapis.
the class PythonSurfaceNamer method getFormattedPrintArgName.
@Override
public /**
* If the argument is a protobuf enum, returns an expression that translates the enum to a
* descriptive string, such as `enums.message_type.enum_type(var.foo.bar).name()`. Otherwise,
* returns the argument as it is.
*/
String getFormattedPrintArgName(ImportTypeTable typeTable, TypeModel type, String variable, List<String> accessors) {
String arg = variable + String.join("", accessors);
// We print the argument as it is if it's not an enum type
if (!(type instanceof ProtoTypeRef) || !((ProtoTypeRef) type).isEnum()) {
return arg;
}
// Find all the parent elements of this enum type, stopping at the top-level message or enum
TypeRef protoType = ((ProtoTypeRef) type).getProtoType();
ProtoElement t = protoType.getEnumType();
List<String> names = new ArrayList<>();
while (!(t instanceof ProtoFile)) {
names.add(t.getSimpleName());
t = t.getParent();
}
// Wrap the enum value with the helper function that translates it to a descriptive string
names.add("enums");
StringBuilder builder = new StringBuilder();
for (String name : Lists.reverse(names)) {
builder.append(name).append(".");
}
builder.setLength(builder.length() - 1);
return builder.append("(").append(arg).append(").name").toString();
}
use of com.google.api.codegen.config.ProtoTypeRef in project toolkit by googleapis.
the class NodeJSSurfaceNamer method returnTypeDoc.
private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodContext methodContext) {
String returnTypeDoc = "";
if (methodContext.getMethodConfig().isPageStreaming()) {
returnTypeDoc = "Array of ";
FieldModel resourcesType = methodContext.getMethodConfig().getPageStreaming().getResourcesField();
if (resourcesType.isMessage()) {
returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType());
} else if (resourcesType.isEnum()) {
returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType());
} else {
// Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter.
returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase();
}
} else if (methodContext.isLongRunningMethodContext()) {
returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/classes/Operation.html} object";
} else {
returnTypeDoc = getTypeNameDoc(typeTable, ProtoTypeRef.create(methodContext.getMethod().getOutputType()));
}
return returnTypeDoc;
}
Aggregations