Search in sources :

Example 1 with TypeRef

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);
    }
}
Also used : TypeRef(com.google.api.tools.framework.model.TypeRef) Duration(org.threeten.bp.Duration) Nullable(javax.annotation.Nullable)

Example 2 with TypeRef

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();
}
Also used : Field(com.google.api.tools.framework.model.Field) ImmutableList(com.google.common.collect.ImmutableList) TypeRef(com.google.api.tools.framework.model.TypeRef) IamResourceProto(com.google.api.codegen.IamResourceProto)

Example 3 with TypeRef

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)));
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) TypeRef(com.google.api.tools.framework.model.TypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Example 4 with TypeRef

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'");
}
Also used : JSTypeTable(com.google.api.codegen.util.js.JSTypeTable) TypeRef(com.google.api.tools.framework.model.TypeRef) EnumValue(com.google.api.tools.framework.model.EnumValue) Test(org.junit.Test)

Example 5 with TypeRef

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");
}
Also used : TypeRef(com.google.api.tools.framework.model.TypeRef) EnumValue(com.google.api.tools.framework.model.EnumValue) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable) Test(org.junit.Test)

Aggregations

TypeRef (com.google.api.tools.framework.model.TypeRef)9 EnumValue (com.google.api.tools.framework.model.EnumValue)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)2 IamResourceProto (com.google.api.codegen.IamResourceProto)1 FieldModel (com.google.api.codegen.config.FieldModel)1 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 CSharpTypeTable (com.google.api.codegen.util.csharp.CSharpTypeTable)1 GoTypeTable (com.google.api.codegen.util.go.GoTypeTable)1 JSTypeTable (com.google.api.codegen.util.js.JSTypeTable)1 PhpTypeTable (com.google.api.codegen.util.php.PhpTypeTable)1 RubyTypeTable (com.google.api.codegen.util.ruby.RubyTypeTable)1 DynamicLangDefaultableParamView (com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView)1 Field (com.google.api.tools.framework.model.Field)1 Nullable (javax.annotation.Nullable)1 Duration (org.threeten.bp.Duration)1