Search in sources :

Example 1 with HeaderRequestParamView

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();
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.tools.framework.model.Method) HeaderRequestParamView(com.google.api.codegen.viewmodel.HeaderRequestParamView) MessageType(com.google.api.tools.framework.model.MessageType)

Example 2 with HeaderRequestParamView

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();
}
Also used : Field(com.google.api.tools.framework.model.Field) ProtoField(com.google.api.codegen.config.ProtoField) ProtoField(com.google.api.codegen.config.ProtoField) ImmutableList(com.google.common.collect.ImmutableList) MessageType(com.google.api.tools.framework.model.MessageType) HeaderRequestParamView(com.google.api.codegen.viewmodel.HeaderRequestParamView)

Aggregations

HeaderRequestParamView (com.google.api.codegen.viewmodel.HeaderRequestParamView)2 MessageType (com.google.api.tools.framework.model.MessageType)2 ImmutableList (com.google.common.collect.ImmutableList)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)1 ProtoField (com.google.api.codegen.config.ProtoField)1 Field (com.google.api.tools.framework.model.Field)1 Method (com.google.api.tools.framework.model.Method)1