Search in sources :

Example 1 with ResourceNameMessageConfigProto

use of com.google.api.codegen.ResourceNameMessageConfigProto in project toolkit by googleapis.

the class ResourceNameMessageConfigs method createMessageResourceTypesConfig.

static ResourceNameMessageConfigs createMessageResourceTypesConfig(DiscoApiModel model, ConfigProto configProto, String defaultPackage, SurfaceNamer languageNamer) {
    ImmutableMap.Builder<String, ResourceNameMessageConfig> builder = ImmutableMap.builder();
    for (ResourceNameMessageConfigProto messageResourceTypesProto : configProto.getResourceNameGenerationList()) {
        ResourceNameMessageConfig messageResourceTypeConfig = ResourceNameMessageConfig.createResourceNameMessageConfig(model.getDiagCollector(), messageResourceTypesProto, defaultPackage);
        builder.put(messageResourceTypeConfig.messageName(), messageResourceTypeConfig);
    }
    ImmutableMap<String, ResourceNameMessageConfig> messageResourceTypeConfigMap = builder.build();
    ListMultimap<String, FieldModel> fieldsByMessage = ArrayListMultimap.create();
    DiscoGapicNamer discoGapicNamer = new DiscoGapicNamer();
    for (Method method : model.getDocument().methods()) {
        String fullName = discoGapicNamer.getRequestTypeName(method, languageNamer).getFullName();
        ResourceNameMessageConfig messageConfig = messageResourceTypeConfigMap.get(fullName);
        if (messageConfig == null) {
            continue;
        }
        for (Schema property : method.parameters().values()) {
            if (messageConfig.getEntityNameForField(property.getIdentifier()) != null) {
                fieldsByMessage.put(fullName, DiscoveryField.create(property, model));
            }
        }
    }
    return new AutoValue_ResourceNameMessageConfigs(messageResourceTypeConfigMap, fieldsByMessage);
}
Also used : ResourceNameMessageConfigProto(com.google.api.codegen.ResourceNameMessageConfigProto) Schema(com.google.api.codegen.discovery.Schema) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap) DiscoGapicNamer(com.google.api.codegen.discogapic.transformer.DiscoGapicNamer)

Example 2 with ResourceNameMessageConfigProto

use of com.google.api.codegen.ResourceNameMessageConfigProto in project toolkit by googleapis.

the class ResourceNameMessageConfigs method createMessageResourceTypesConfig.

@Nullable
public static ResourceNameMessageConfigs createMessageResourceTypesConfig(Model model, ConfigProto configProto, String defaultPackage) {
    ImmutableMap.Builder<String, ResourceNameMessageConfig> builder = ImmutableMap.builder();
    for (ResourceNameMessageConfigProto messageResourceTypesProto : configProto.getResourceNameGenerationList()) {
        ResourceNameMessageConfig messageResourceTypeConfig = ResourceNameMessageConfig.createResourceNameMessageConfig(model.getDiagCollector(), messageResourceTypesProto, defaultPackage);
        builder.put(messageResourceTypeConfig.messageName(), messageResourceTypeConfig);
    }
    ImmutableMap<String, ResourceNameMessageConfig> messageResourceTypeConfigMap = builder.build();
    ListMultimap<String, FieldModel> fieldsByMessage = ArrayListMultimap.create();
    Set<String> seenProtoFiles = new HashSet<>();
    for (ProtoFile protoFile : model.getFiles()) {
        if (!seenProtoFiles.contains(protoFile.getSimpleName())) {
            seenProtoFiles.add(protoFile.getSimpleName());
            for (MessageType msg : protoFile.getMessages()) {
                ResourceNameMessageConfig messageConfig = messageResourceTypeConfigMap.get(msg.getFullName());
                if (messageConfig == null) {
                    continue;
                }
                for (Field field : msg.getFields()) {
                    if (messageConfig.getEntityNameForField(field.getSimpleName()) != null) {
                        fieldsByMessage.put(msg.getFullName(), new ProtoField(field));
                    }
                }
            }
        }
    }
    return new AutoValue_ResourceNameMessageConfigs(messageResourceTypeConfigMap, fieldsByMessage);
}
Also used : ProtoFile(com.google.api.tools.framework.model.ProtoFile) ImmutableMap(com.google.common.collect.ImmutableMap) Field(com.google.api.tools.framework.model.Field) ResourceNameMessageConfigProto(com.google.api.codegen.ResourceNameMessageConfigProto) MessageType(com.google.api.tools.framework.model.MessageType) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Aggregations

ResourceNameMessageConfigProto (com.google.api.codegen.ResourceNameMessageConfigProto)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DiscoGapicNamer (com.google.api.codegen.discogapic.transformer.DiscoGapicNamer)1 Method (com.google.api.codegen.discovery.Method)1 Schema (com.google.api.codegen.discovery.Schema)1 Field (com.google.api.tools.framework.model.Field)1 MessageType (com.google.api.tools.framework.model.MessageType)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1 HashSet (java.util.HashSet)1 Nullable (javax.annotation.Nullable)1