use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class GrpcElementDocTransformer method generateMessageDocs.
private List<GrpcElementDocView> generateMessageDocs(ModelTypeTable typeTable, SurfaceNamer namer, ProtoContainerElement containerElement) {
ImmutableList.Builder<GrpcElementDocView> messageDocs = ImmutableList.builder();
for (MessageType message : containerElement.getMessages()) {
// 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(typeTable, namer, message));
doc.packageName(message.getFile().getFullName());
messageDocs.add(doc.build());
}
return messageDocs.build();
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class ProtoParser method getResourceDescriptorConfigMap.
/**
* Return a Map of Unified Resource Types to a ResourceDescriptorConfig object.
*/
public Map<String, ResourceDescriptorConfig> getResourceDescriptorConfigMap(List<ProtoFile> protoFiles, DiagCollector diagCollector) {
ImmutableMap.Builder<String, ResourceDescriptorConfig> mapBuilder = ImmutableMap.builder();
// Maps base names to ResourceDescriptors. Used to check redeclarations.
Map<String, ResourceDescriptor> localDefs = new LinkedHashMap<>();
// Skip unnecessary file parsing.
if (!enableProtoAnnotations)
return mapBuilder.build();
for (ProtoFile protoFile : protoFiles) {
List<ResourceDescriptor> resourceDescriptors = new ArrayList<>();
// Get Resource[Set] definitions from file-level annotations.
for (ResourceDescriptor definition : getFileLevelResourceDescriptors(protoFile)) {
collectResourceDescriptor(diagCollector, localDefs, mapBuilder, definition, protoFile, false);
}
// Get Resource[Set] definitions from fields in message types.
for (MessageType message : protoFile.getMessages()) {
ResourceDescriptor definition = getResourceDescriptor(message);
if (definition != null) {
collectResourceDescriptor(diagCollector, localDefs, mapBuilder, definition, protoFile, true);
}
}
}
return mapBuilder.build();
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class ModelTypeNameConverterTestUtil method getTestType.
public static TypeRef getTestType(String fileName, TemporaryFolder tempDir, String... path) {
String yamlFileName = fileName + ".yaml";
fileName = fileName + ".proto";
TestDataLocator locator = TestDataLocator.create(CodegenTestUtil.class);
locator.addTestDataSource(CodegenTestUtil.class, "testsrc/common");
Model model = CodegenTestUtil.readModel(locator, tempDir, new String[] { fileName }, new String[] { yamlFileName });
ProtoContainerElement container = getElementWithName(model.getFiles(), fileName);
if (container == null) {
throw new IllegalStateException("file not found: " + fileName);
}
for (int i = 0; i < path.length; i++) {
String pathElement = path[i];
MessageType messageType = getElementWithName(container.getMessages(), pathElement);
EnumType enumType = getElementWithName(container.getEnums(), pathElement);
if (messageType != null) {
container = messageType;
} else if (enumType != null && i == path.length - 1) {
return TypeRef.of(enumType);
} else if (enumType != null) {
throw new IllegalStateException("enum type cannot contain further elements: " + enumType);
} else {
throw new IllegalStateException("element not found: " + pathElement);
}
}
if (container instanceof MessageType) {
return TypeRef.of((MessageType) container);
}
throw new IllegalStateException("not a type: " + container);
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class ProtoParserTest method testGetResourceType.
@Test
public void testGetResourceType() {
MessageType getShelfRequest = libraryProtoFile.getMessages().stream().filter(m -> m.getSimpleName().equals("GetShelfRequest")).findFirst().get();
Field shelves = getShelfRequest.getFields().stream().filter(f -> f.getSimpleName().equals("name")).findFirst().get();
String shelfType = protoParser.getResourceReference(shelves).getType();
assertThat(shelfType).isEqualTo("library.googleapis.com/Shelf");
}
use of com.google.api.tools.framework.model.MessageType in project toolkit by googleapis.
the class ResourceNameMessageConfigs method createFromAnnotations.
@VisibleForTesting
static ResourceNameMessageConfigs createFromAnnotations(DiagCollector diagCollector, List<ProtoFile> protoFiles, Map<String, ResourceNameConfig> resourceNameConfigs, ProtoParser parser, Map<String, ResourceDescriptorConfig> descriptorConfigMap, Map<String, List<ResourceDescriptorConfig>> childParentResourceMap) {
ImmutableMap.Builder<String, ResourceNameMessageConfig> builder = ImmutableMap.builder();
for (ProtoFile protoFile : protoFiles) {
for (MessageType message : protoFile.getMessages()) {
ImmutableListMultimap.Builder<String, String> fieldEntityMapBuilder = ImmutableListMultimap.builder();
// Handle resource definitions.
ResourceDescriptor resourceDescriptor = parser.getResourceDescriptor(message);
if (resourceDescriptor != null) {
loadFieldEntityPairFromResourceAnnotation(fieldEntityMapBuilder, resourceDescriptor, message);
}
// Handle resource references.
loadFieldEntityPairFromResourceReferenceAnnotation(fieldEntityMapBuilder, parser, message, resourceNameConfigs, descriptorConfigMap, childParentResourceMap);
ImmutableListMultimap<String, String> fieldEntityMap = fieldEntityMapBuilder.build();
if (fieldEntityMap.size() > 0) {
ResourceNameMessageConfig messageConfig = new AutoValue_ResourceNameMessageConfig(message.getFullName(), fieldEntityMap);
builder.put(messageConfig.messageName(), messageConfig);
}
}
}
ImmutableMap<String, ResourceNameMessageConfig> map = builder.build();
return new AutoValue_ResourceNameMessageConfigs(map, createFieldsByMessage(protoFiles, map));
}
Aggregations