use of com.google.api.codegen.viewmodel.HeaderRequestParamView 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()) {
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.codegen.viewmodel.HeaderRequestParamView 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();
}
Aggregations