use of com.google.api.tools.framework.model.Diag in project toolkit by googleapis.
the class GrpcMetadataGenerator method process.
@Override
protected void process() throws Exception {
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return;
}
Map<String, Doc> docs = generate(model);
ToolUtil.writeFiles(docs, options.get(OUTPUT_DIR));
}
use of com.google.api.tools.framework.model.Diag in project toolkit by googleapis.
the class FieldConfig method createFieldConfig.
/**
* Package-private since this is not used outside the config package.
*/
static FieldConfig createFieldConfig(DiagCollector diagCollector, ResourceNameMessageConfigs messageConfigs, Map<String, String> fieldNamePatterns, Map<String, ResourceNameConfig> resourceNameConfigs, FieldModel field, ResourceNameTreatment treatment, ResourceNameTreatment defaultResourceNameTreatment) {
String messageFieldEntityName = null;
String flattenedFieldEntityName = null;
if (messageConfigs != null && messageConfigs.fieldHasResourceName(field)) {
messageFieldEntityName = messageConfigs.getFieldResourceName(field);
}
if (fieldNamePatterns != null) {
flattenedFieldEntityName = fieldNamePatterns.get(field.getNameAsParameter());
}
if (flattenedFieldEntityName == null) {
flattenedFieldEntityName = messageFieldEntityName;
}
if (treatment == null || treatment.equals(ResourceNameTreatment.UNSET_TREATMENT)) {
// the method-level default and the specified entities.
if (flattenedFieldEntityName == null) {
treatment = ResourceNameTreatment.NONE;
} else {
treatment = defaultResourceNameTreatment;
}
}
ResourceNameConfig messageFieldResourceNameConfig = getResourceNameConfig(diagCollector, resourceNameConfigs, messageFieldEntityName);
ResourceNameConfig flattenedFieldResourceNameConfig = getResourceNameConfig(diagCollector, resourceNameConfigs, flattenedFieldEntityName);
if (messageFieldResourceNameConfig != null && !messageFieldResourceNameConfig.equals(flattenedFieldResourceNameConfig)) {
// We support the case of the flattenedField using a specific resource name type when the
// messageField uses a oneof containing that type, or when the messageField accepts any
// resource name, or for Discovery fields.
ResourceNameType resourceTypeName = messageFieldResourceNameConfig.getResourceNameType();
boolean ok = resourceTypeName == ResourceNameType.ANY;
if (resourceTypeName == ResourceNameType.ONEOF) {
ResourceNameOneofConfig oneofConfig = (ResourceNameOneofConfig) messageFieldResourceNameConfig;
ok = oneofConfig.getResourceNameConfigs().contains(flattenedFieldResourceNameConfig);
}
if (!ok) {
Diag error = Diag.error(SimpleLocation.TOPLEVEL, "Multiple entity names specified for field: " + field.getFullName() + ": [" + flattenedFieldEntityName + ", " + messageFieldEntityName + "]");
if (diagCollector == null) {
throw new IllegalArgumentException(error.toString());
}
diagCollector.addDiag(error);
return null;
}
}
validate(messageConfigs, field, treatment, flattenedFieldResourceNameConfig);
return createFieldConfig(field, treatment, flattenedFieldResourceNameConfig, messageFieldResourceNameConfig);
}
use of com.google.api.tools.framework.model.Diag in project toolkit by googleapis.
the class FieldConfig method getResourceNameConfig.
private static ResourceNameConfig getResourceNameConfig(DiagCollector diagCollector, Map<String, ResourceNameConfig> resourceNameConfigs, String entityName) {
if (entityName != null) {
if (entityName.equals(AnyResourceNameConfig.GAPIC_CONFIG_ANY_VALUE)) {
return AnyResourceNameConfig.instance();
} else {
ResourceNameConfig flattenedFieldResourceNameConfig = resourceNameConfigs.get(entityName);
if (flattenedFieldResourceNameConfig == null) {
Diag error = Diag.error(SimpleLocation.TOPLEVEL, "No resourceNameConfig with entity_name \"%s\"", entityName);
if (diagCollector == null) {
throw new IllegalArgumentException(error.toString());
}
diagCollector.addDiag(error);
return null;
}
return flattenedFieldResourceNameConfig;
}
}
return null;
}
use of com.google.api.tools.framework.model.Diag in project toolkit by googleapis.
the class GapicTestBase2 method setupModel.
@Override
protected void setupModel() {
super.setupModel();
gapicConfig = CodegenTestUtil.readConfig(model.getDiagCollector(), getTestDataLocator(), gapicConfigFileNames);
if (!Strings.isNullOrEmpty(packageConfigFileName)) {
try {
URI packageConfigUrl = getTestDataLocator().findTestData(packageConfigFileName).toURI();
String contents = new String(Files.readAllBytes(Paths.get(packageConfigUrl)), StandardCharsets.UTF_8);
packageConfig = PackageMetadataConfig.createFromString(contents);
} catch (IOException | URISyntaxException e) {
throw new IllegalArgumentException("Problem creating packageConfig");
}
}
// TODO (garrettjones) depend on the framework to take care of this.
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
throw new IllegalArgumentException("Problem creating Generator");
}
}
use of com.google.api.tools.framework.model.Diag in project toolkit by googleapis.
the class ConfigGeneratorApi method process.
@Override
protected void process() throws Exception {
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return;
}
String outputPath = options.get(OUTPUT_FILE);
Map<String, String> outputFiles = generateConfig(outputPath);
ToolUtil.writeFiles(outputFiles, "");
}
Aggregations