Search in sources :

Example 11 with MessageType

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();
}
Also used : Field(com.google.api.tools.framework.model.Field) MessageType(com.google.api.tools.framework.model.MessageType) GapicCodeGeneratorAnnotationsTest(com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest) Test(org.junit.Test)

Example 12 with MessageType

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);
}
Also used : ProtoElement(com.google.api.tools.framework.model.ProtoElement) ProtoFile(com.google.api.tools.framework.model.ProtoFile) MessageType(com.google.api.tools.framework.model.MessageType)

Example 13 with MessageType

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();
}
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 14 with MessageType

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

Example 15 with MessageType

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

Aggregations

MessageType (com.google.api.tools.framework.model.MessageType)16 ProtoFile (com.google.api.tools.framework.model.ProtoFile)7 Field (com.google.api.tools.framework.model.Field)6 ImmutableList (com.google.common.collect.ImmutableList)5 GrpcElementDocView (com.google.api.codegen.viewmodel.GrpcElementDocView)3 GrpcMessageDocView (com.google.api.codegen.viewmodel.GrpcMessageDocView)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ResourceDescriptor (com.google.api.ResourceDescriptor)2 GapicCodeGeneratorAnnotationsTest (com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest)2 HeaderRequestParamView (com.google.api.codegen.viewmodel.HeaderRequestParamView)2 ProtoElement (com.google.api.tools.framework.model.ProtoElement)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 ResourceNameMessageConfigProto (com.google.api.codegen.ResourceNameMessageConfigProto)1 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)1 ProtoField (com.google.api.codegen.config.ProtoField)1 ResourceDescriptorConfig (com.google.api.codegen.config.ResourceDescriptorConfig)1 TypeName (com.google.api.codegen.util.TypeName)1 EnumType (com.google.api.tools.framework.model.EnumType)1 Method (com.google.api.tools.framework.model.Method)1