use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceTransformer method createLongRunningDescriptors.
private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
List<LongRunningOperationDetailView> result = new ArrayList<>();
for (MethodModel method : context.getLongRunningMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
LongRunningConfig lroConfig = methodContext.getLongRunningConfig();
TypeModel returnType = lroConfig.getReturnType();
TypeModel metadataType = lroConfig.getMetadataType();
result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
}
return result;
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method createLongRunningDescriptors.
private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
List<LongRunningOperationDetailView> result = new ArrayList<>();
for (MethodModel method : context.getLongRunningMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
LongRunningConfig lroConfig = methodContext.getLongRunningConfig();
TypeModel returnType = lroConfig.getReturnType();
TypeModel metadataType = lroConfig.getMetadataType();
result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
}
return result;
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testScopeTableGetTypeModel.
@Test
public void testScopeTableGetTypeModel() {
TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string"));
assertThat(parent.put("str", stringTypeModel, "String")).isTrue();
assertThat(parent.getTypeModel("str")).isEqualTo(stringTypeModel);
assertThat(parent.getTypeName("str")).isEqualTo("String");
assertThat(parent.getTypeModel("book")).isNull();
assertThat(parent.getTypeName("book")).isNull();
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableMapKeyUnquoatedStringFail.
@Test
public void testAccessorNewVariableMapKeyUnquoatedStringFail() {
Scanner scanner = new Scanner("old_var.property{unquoted_string}");
when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
TypeModel oldVarTypeModel = mock(TypeModel.class);
assertThat(parent.put("old_var", oldVarTypeModel, "OldVarType")).isTrue();
when(oldVarTypeModel.isMessage()).thenReturn(true);
when(oldVarTypeModel.isRepeated()).thenReturn(false);
when(oldVarTypeModel.isMap()).thenReturn(false);
FieldModel propertyFieldModel = mock(FieldModel.class);
when(oldVarTypeModel.getField("property")).thenReturn(propertyFieldModel);
TypeModel propertyTypeModel = mock(TypeModel.class);
when(propertyFieldModel.getType()).thenReturn(propertyTypeModel);
when(propertyTypeModel.isRepeated()).thenReturn(true);
when(propertyTypeModel.isMap()).thenReturn(true);
when(namer.getFieldGetFunctionName(propertyFieldModel)).thenReturn("getProperty");
when(namer.getFieldAccessorName(propertyFieldModel)).thenReturn(".getProperty()");
TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string"));
when(propertyTypeModel.getMapKeyType()).thenReturn(stringTypeModel);
when(propertyTypeModel.getMapValueType()).thenReturn(stringTypeModel);
try {
accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
fail();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage()).contains("expected string type for map key");
}
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableScalarTypeForCollectionFail.
@Test
public void testAccessorNewVariableScalarTypeForCollectionFail() {
TypeModel oldVarTypeModel = mock(TypeModel.class);
assertThat(parent.put("old_var", oldVarTypeModel, "OldVarTypeName")).isTrue();
Scanner scanner = new Scanner("old_var");
when(oldVarTypeModel.isRepeated()).thenReturn(false);
when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
when(namer.getAndSaveTypeName(typeTable, oldVarTypeModel)).thenReturn("OldVarTypeName");
try {
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", true);
fail();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage()).contains("is not a repeated field");
}
}
Aggregations