use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class PythonImportSectionTransformer method generateTypesProtoImports.
private List<ImportFileView> generateTypesProtoImports(Model model, GapicProductConfig productConfig) {
ModelTypeTable typeTable = emptyTypeTable(productConfig);
Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
// Save proto file import names to the type table for disambiguation.
List<ProtoFile> protoFileDependencies = model.getFiles();
populateTypeTable(protoFileDependencies, typeTable);
// Get disambiguated imports.
for (Map.Entry<String, TypeAlias> entry : typeTable.getImports().entrySet()) {
imports.add(generateAppImport(entry.getKey(), entry.getValue().getNickname()));
}
return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class ProtoFileView method protoFiles.
private Set<ProtoFile> protoFiles(Field field) {
Set<ProtoFile> fields = new HashSet<ProtoFile>();
if (field.getType().getKind() != Type.TYPE_MESSAGE) {
return fields;
}
MessageType messageType = field.getType().getMessageType();
fields.add(messageType.getFile());
for (Field f : messageType.getNonCyclicFields()) {
fields.addAll(protoFiles(f));
}
return fields;
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class GapicProductConfig method create.
/**
* Creates an instance of GapicProductConfig based on ConfigProto, linking up API interface
* configurations with specified interfaces in interfaceConfigMap. On errors, null will be
* returned, and diagnostics are reported to the model.
*/
@Nullable
public static GapicProductConfig create(Model model, ConfigProto configProto) {
// Get the proto file containing the first interface listed in the config proto, and use it as
// the assigned file for generated resource names, and to get the default message namespace
ProtoFile file = model.getSymbolTable().lookupInterface(configProto.getInterfaces(0).getName()).getFile();
String defaultPackage = file.getProto().getPackage();
ResourceNameMessageConfigs messageConfigs = ResourceNameMessageConfigs.createMessageResourceTypesConfig(model, configProto, defaultPackage);
ImmutableMap<String, ResourceNameConfig> resourceNameConfigs = createResourceNameConfigs(model.getDiagCollector(), configProto, file);
TransportProtocol transportProtocol = TransportProtocol.GRPC;
LanguageSettingsProto settings = configProto.getLanguageSettings().get(configProto.getLanguage());
if (settings == null) {
settings = LanguageSettingsProto.getDefaultInstance();
}
ImmutableMap<String, InterfaceConfig> interfaceConfigMap = createInterfaceConfigMap(model.getDiagCollector(), configProto, settings, messageConfigs, resourceNameConfigs, model.getSymbolTable());
ImmutableList<String> copyrightLines = null;
ImmutableList<String> licenseLines = null;
try {
LicenseHeaderProto licenseHeader = configProto.getLicenseHeader().toBuilder().mergeFrom(settings.getLicenseHeaderOverride()).build();
copyrightLines = loadCopyrightLines(model.getDiagCollector(), licenseHeader);
licenseLines = loadLicenseLines(model.getDiagCollector(), licenseHeader);
} catch (Exception e) {
model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Exception: %s", e.getMessage()));
e.printStackTrace(System.err);
throw new RuntimeException(e);
}
String configSchemaVersion = configProto.getConfigSchemaVersion();
// TODO(eoogbe): Move the validation logic to GAPIC config advisor.
if (Strings.isNullOrEmpty(configSchemaVersion)) {
model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "config_schema_version field is required in GAPIC yaml."));
}
if (interfaceConfigMap == null || copyrightLines == null || licenseLines == null) {
return null;
}
return new AutoValue_GapicProductConfig(interfaceConfigMap, settings.getPackageName(), settings.getDomainLayerLocation(), settings.getReleaseLevel(), messageConfigs, copyrightLines, licenseLines, resourceNameConfigs, transportProtocol, createResponseFieldConfigMap(messageConfigs, resourceNameConfigs), configSchemaVersion);
}
Aggregations