use of com.google.api.tools.framework.model.TypeRef in project toolkit by googleapis.
the class LongRunningConfig method createLongRunningConfig.
/**
* Creates an instance of LongRunningConfig based on LongRunningConfigProto.
*/
@Nullable
public static LongRunningConfig createLongRunningConfig(Model model, DiagCollector diagCollector, LongRunningConfigProto longRunningConfigProto) {
boolean error = false;
TypeRef returnType = model.getSymbolTable().lookupType(longRunningConfigProto.getReturnType());
TypeRef metadataType = model.getSymbolTable().lookupType(longRunningConfigProto.getMetadataType());
if (returnType == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Type not found for long running config: '%s'", longRunningConfigProto.getReturnType()));
error = true;
} else if (!returnType.isMessage()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Type for long running config is not a message: '%s'", longRunningConfigProto.getReturnType()));
error = true;
}
if (metadataType == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Metadata type not found for long running config: '%s'", longRunningConfigProto.getMetadataType()));
error = true;
} else if (!metadataType.isMessage()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Metadata type for long running config is not a message: '%s'", longRunningConfigProto.getMetadataType()));
error = true;
}
Duration initialPollDelay = Duration.ofMillis(longRunningConfigProto.getInitialPollDelayMillis());
if (initialPollDelay.compareTo(Duration.ZERO) < 0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Initial poll delay must be provided and set to a positive number: '%s'", longRunningConfigProto.getInitialPollDelayMillis()));
error = true;
}
double pollDelayMultiplier = longRunningConfigProto.getPollDelayMultiplier();
if (pollDelayMultiplier <= 1.0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Poll delay multiplier must be provided and be greater or equal than 1.0: '%s'", longRunningConfigProto.getPollDelayMultiplier()));
error = true;
}
Duration maxPollDelay = Duration.ofMillis(longRunningConfigProto.getMaxPollDelayMillis());
if (maxPollDelay.compareTo(initialPollDelay) < 0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Max poll delay must be provided and set be equal or greater than initial poll delay: '%s'", longRunningConfigProto.getMaxPollDelayMillis()));
error = true;
}
Duration totalPollTimeout = Duration.ofMillis(longRunningConfigProto.getTotalPollTimeoutMillis());
if (totalPollTimeout.compareTo(maxPollDelay) < 0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Total poll timeout must be provided and be be equal or greater than max poll delay: '%s'", longRunningConfigProto.getTotalPollTimeoutMillis()));
error = true;
}
if (error) {
return null;
} else {
return new AutoValue_LongRunningConfig(new ProtoTypeRef(returnType), new ProtoTypeRef(metadataType), longRunningConfigProto.getImplementsDelete(), longRunningConfigProto.getImplementsCancel(), initialPollDelay, pollDelayMultiplier, maxPollDelay, totalPollTimeout);
}
}
use of com.google.api.tools.framework.model.TypeRef in project toolkit by googleapis.
the class GapicInterfaceConfig method createIamResources.
/**
* Creates a list of fields that can be turned into IAM resources
*/
private static ImmutableList<FieldModel> createIamResources(Model model, List<IamResourceProto> resources) {
ImmutableList.Builder<FieldModel> fields = ImmutableList.builder();
for (IamResourceProto resource : resources) {
TypeRef type = model.getSymbolTable().lookupType(resource.getType());
if (type == null) {
throw new IllegalArgumentException("type not found: " + resource.getType());
}
if (!type.isMessage()) {
throw new IllegalArgumentException("type must be a message: " + type);
}
Field field = type.getMessageType().lookupField(resource.getField());
if (field == null) {
throw new IllegalArgumentException(String.format("type %s does not have field %s", resource.getType(), resource.getField()));
}
fields.add(new ProtoField(field));
}
return fields.build();
}
use of com.google.api.tools.framework.model.TypeRef in project toolkit by googleapis.
the class PythonSurfaceNamer method getReturnDocLines.
@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
MethodConfig methodConfig = methodContext.getMethodConfig();
TypeRef outputType = ((GapicMethodConfig) methodConfig).getMethod().getOutputType();
if (ServiceMessages.s_isEmptyType(outputType)) {
return ImmutableList.<String>of();
}
String returnTypeName = methodConfig.isLongRunningOperation() ? "google.gax._OperationFuture" : getModelTypeFormatter().getFullNameFor(outputType);
String classInfo = PythonDocstringUtil.napoleonType(returnTypeName, getVersionedDirectoryNamespace());
if (((GapicMethodConfig) methodConfig).getMethod().getResponseStreaming()) {
return ImmutableList.of("Iterable[" + classInfo + "].");
}
if (methodConfig.isPageStreaming()) {
FieldModel fieldModel = methodConfig.getPageStreaming().getResourcesField();
return ImmutableList.of("A :class:`~google.gax.PageIterator` instance. By default, this", "is an iterable of " + annotateWithClass(getResponseTypeNameForElementType(fieldModel.getType())) + " instances.", "This object can also be configured to iterate over the pages", "of the response through the `options` parameter.");
}
return ImmutableList.of(String.format("A %s instance.", annotateWithClass(classInfo)));
}
use of com.google.api.tools.framework.model.TypeRef in project toolkit by googleapis.
the class NodeJSModelTypeNameConverterTest method testGetEnumValue.
@Test
public void testGetEnumValue() {
String packageName = "library.v1";
TypeRef type = ModelTypeNameConverterTestUtil.getTestEnumType(tempDir);
EnumValue value = type.getEnumType().getValues().get(0);
NodeJSModelTypeNameConverter converter = new NodeJSModelTypeNameConverter(packageName);
Truth.assertThat(converter.getEnumValue(type, value).getValueAndSaveTypeNicknameIn(new JSTypeTable(packageName))).isEqualTo("'GOOD'");
}
use of com.google.api.tools.framework.model.TypeRef in project toolkit by googleapis.
the class PhpModelTypeNameConverterTest method testGetEnumValue.
@Test
public void testGetEnumValue() {
String packageName = "Google\\Example\\Library\\V1";
TypeRef type = ModelTypeNameConverterTestUtil.getTestEnumType(tempDir);
EnumValue value = type.getEnumType().getValues().get(0);
PhpModelTypeNameConverter converter = new PhpModelTypeNameConverter(packageName);
Truth.assertThat(converter.getEnumValue(type, value).getValueAndSaveTypeNicknameIn(new PhpTypeTable(packageName))).isEqualTo("Book_Rating::GOOD");
}
Aggregations