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