use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class ProtoParserTest method testGetEmptyResource.
@Test
public void testGetEmptyResource() {
MessageType book = libraryProtoFile.getMessages().stream().filter(m -> m.getSimpleName().equals("Book")).findFirst().get();
Field authorBookField = book.getFields().stream().filter(f -> f.getSimpleName().equals("author")).findFirst().get();
assertThat(protoParser.getResourceReference(authorBookField)).isNull();
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class CSharpModelTypeNameConverter method getTypeName.
@Override
public TypeName getTypeName(ProtoElement elem) {
// Handle special wrapper types first
String wrapper = WRAPPER_TYPE_MAP.getOrDefault(elem.getFullName(), null);
if (wrapper != null) {
return typeNameConverter.getTypeName(wrapper);
}
// Handle nested types, construct the required type prefix
ProtoElement parentEl = elem.getParent();
String shortNamePrefix = "";
while (parentEl != null && parentEl instanceof MessageType) {
shortNamePrefix = parentEl.getSimpleName() + "+Types+" + shortNamePrefix;
parentEl = parentEl.getParent();
}
String prefix = "";
if (parentEl instanceof ProtoFile) {
ProtoFile protoFile = (ProtoFile) parentEl;
String namespace = protoFile.getProto().getOptions().getCsharpNamespace();
if (Strings.isNullOrEmpty(namespace)) {
for (String name : Splitter.on('.').split(parentEl.getFullName())) {
prefix += Name.from(name).toUpperCamelAndDigits() + ".";
}
} else {
prefix = namespace + ".";
}
}
String shortName = shortNamePrefix + elem.getSimpleName();
return typeNameConverter.getTypeName(prefix + shortName);
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class HeaderRequestParamTransformer method generateHeaderRequestParams.
public List<HeaderRequestParamView> generateHeaderRequestParams(MethodContext context) {
if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableList.of();
}
GapicMethodConfig methodConfig = (GapicMethodConfig) context.getMethodConfig();
Method method = methodConfig.getMethod();
SurfaceNamer namer = context.getNamer();
if (method.getInputType() == null || !method.getInputType().isMessage() || // Request header parameters not supported for methods that stream requests.
method.getRequestStreaming()) {
return ImmutableList.of();
}
ImmutableList.Builder<HeaderRequestParamView> headerRequestParams = ImmutableList.builder();
MessageType inputMessageType = method.getInputType().getMessageType();
for (String headerRequestParam : methodConfig.getHeaderRequestParams()) {
headerRequestParams.add(generateHeaderRequestParam(headerRequestParam, inputMessageType, namer));
}
return headerRequestParams.build();
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class HeaderRequestParamTransformer method generateHeaderRequestParam.
private HeaderRequestParamView generateHeaderRequestParam(String headerRequestParam, MessageType inputMessageType, SurfaceNamer namer) {
String[] fieldNameTokens = headerRequestParam.split("\\.");
ImmutableList.Builder<String> gettersChain = ImmutableList.builder();
MessageType subMessageType = inputMessageType;
for (String fieldNameToken : fieldNameTokens) {
Field matchingField = subMessageType.lookupField(fieldNameToken);
if (matchingField == null) {
throw new IllegalArgumentException("Unknown field name token '" + fieldNameToken + "' in header request param '" + headerRequestParam + "'");
}
String matchingFieldGetter = namer.getFieldGetFunctionName(new ProtoField(matchingField));
gettersChain.add(matchingFieldGetter);
if (matchingField.getType() != null && matchingField.getType().isMessage()) {
subMessageType = matchingField.getType().getMessageType();
}
}
HeaderRequestParamView.Builder headerParam = HeaderRequestParamView.newBuilder().fullyQualifiedName(headerRequestParam).gettersChain(gettersChain.build());
return headerParam.build();
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class GrpcElementDocTransformer method generateMessageDocs.
private List<GrpcElementDocView> generateMessageDocs(GapicProductConfig productConfig, ModelTypeTable typeTable, SurfaceNamer namer, Collection<MessageType> messages) {
ImmutableList.Builder<GrpcElementDocView> messageDocs = ImmutableList.builder();
for (MessageType message : messages) {
// Doesn't have to document map entries because a dictionary is used.
if (message.isMapEntry()) {
continue;
}
GrpcMessageDocView.Builder doc = GrpcMessageDocView.newBuilder();
doc.name(namer.getMessageTypeName(typeTable, message));
doc.fullName(typeTable.getFullNameFor(TypeRef.of(message)));
doc.fileUrl(GapicParser.getFileUrl(message.getFile()));
doc.lines(namer.getDocLines(GapicParser.getDocString(message)));
doc.properties(generateMessagePropertyDocs(typeTable, namer, FieldConfig.toFieldTypeIterableFromField(message.getFields())));
doc.elementDocs(generateElementDocs(productConfig, typeTable, namer, message));
doc.packageName(message.getFile().getFullName());
messageDocs.add(doc.build());
}
return messageDocs.build();
}
Aggregations