use of com.google.api.codegen.LanguageSettingsProto in project toolkit by googleapis.
the class GapicProductConfig method create.
public static GapicProductConfig create(DiscoApiModel model, ConfigProto configProto, SurfaceNamer namer) {
String defaultPackage = configProto.getLanguageSettingsMap().get(configProto.getLanguage()).getPackageName();
ResourceNameMessageConfigs messageConfigs = ResourceNameMessageConfigs.createMessageResourceTypesConfig(model, configProto, defaultPackage, namer);
ImmutableMap<String, ResourceNameConfig> resourceNameConfigs = createResourceNameConfigs(model.getDiagCollector(), configProto, null);
TransportProtocol transportProtocol = TransportProtocol.HTTP;
LanguageSettingsProto settings = configProto.getLanguageSettingsMap().get(configProto.getLanguage());
if (settings == null) {
settings = LanguageSettingsProto.getDefaultInstance();
}
ImmutableMap<String, InterfaceConfig> interfaceConfigMap = createDiscoGapicInterfaceConfigMap(model, configProto, settings, messageConfigs, resourceNameConfigs);
ImmutableList<String> copyrightLines;
ImmutableList<String> licenseLines;
try {
LicenseHeaderProto licenseHeader = configProto.getLicenseHeader().toBuilder().mergeFrom(settings.getLicenseHeaderOverride()).build();
copyrightLines = getResourceLines(licenseHeader.getCopyrightFile());
licenseLines = getResourceLines(licenseHeader.getLicenseFile());
} 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."));
}
return new AutoValue_GapicProductConfig(interfaceConfigMap, settings.getPackageName(), settings.getDomainLayerLocation(), settings.getReleaseLevel(), messageConfigs, copyrightLines, licenseLines, resourceNameConfigs, transportProtocol, createResponseFieldConfigMap(messageConfigs, resourceNameConfigs), configSchemaVersion);
}
use of com.google.api.codegen.LanguageSettingsProto in project toolkit by googleapis.
the class LanguageSettingsRule method collectAdvice.
@Override
public List<String> collectAdvice(Model model, ConfigProto configProto) {
String packageName = getPackageName(model);
ImmutableList.Builder<String> messages = ImmutableList.builder();
for (Map.Entry<String, LanguageTransformer.LanguageFormatter> entry : LanguageTransformer.LANGUAGE_FORMATTERS.entrySet()) {
String language = entry.getKey();
LanguageSettingsProto languageSettingsProto = configProto.getLanguageSettingsOrDefault(language, null);
if (languageSettingsProto == null) {
String formattedPackageName = entry.getValue().getFormattedPackageName(packageName);
messages.add(String.format("Missing language_settings for key %s.%n" + "Did you mean:%n" + " language_settings:%n" + " # ...%n" + " %s:%n" + " package_name: %s%n%n", language, language, formattedPackageName));
} else if (languageSettingsProto.getPackageName().isEmpty()) {
String formattedPackageName = entry.getValue().getFormattedPackageName(packageName);
messages.add(String.format("Missing package_name in language_settings of key %s.%n" + "Did you mean:%n" + " %s:%n" + " # ...%n" + " package_name: %s%n%n", language, language, formattedPackageName));
}
}
return messages.build();
}
use of com.google.api.codegen.LanguageSettingsProto 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