use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariablePageStreamingResponse.
@Test
public void testAccessorNewVariablePageStreamingResponse() {
Scanner scanner = new Scanner("$resp");
when(config.getPageStreaming()).thenReturn(pageStreamingConfig);
when(pageStreamingConfig.getResourcesFieldConfig()).thenReturn(resourceFieldConfig);
when(featureConfig.useResourceNameFormatOption(resourceFieldConfig)).thenReturn(false);
FieldModel fieldModel = mock(FieldModel.class);
when(resourceFieldConfig.getField()).thenReturn(fieldModel);
TypeModel typeModel = mock(TypeModel.class);
when(fieldModel.getType()).thenReturn(typeModel);
when(typeModel.makeOptional()).thenReturn(typeModel);
when(typeTable.getNicknameFor(typeModel)).thenReturn("TypeName");
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("sampleResponseVarName");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("TypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(typeModel);
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableResponse.
@Test
public void testAccessorNewVariableResponse() {
Scanner scanner = new Scanner("$resp");
when(config.getPageStreaming()).thenReturn(null);
TypeModel typeModel = mock(TypeModel.class);
when(typeTable.getNicknameFor(typeModel)).thenReturn("TypeName");
when(model.getOutputType()).thenReturn(typeModel);
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("sampleResponseVarName");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("TypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(typeModel);
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class RubyGapicSurfaceTransformer method generateVersionIndexView.
private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
Iterable<? extends InterfaceModel> interfaces = model.getInterfaces(productConfig);
for (InterfaceModel apiInterface : interfaces) {
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
if (interfaceConfig == null) {
continue;
}
GapicInterfaceContext context = createContext(apiInterface, productConfig);
requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
}
// append any additional types
Set<String> requireTypes = new HashSet<>();
for (TypeModel type : model.getAdditionalTypes()) {
if (type instanceof ProtoTypeRef) {
ProtoTypeRef t = (ProtoTypeRef) type;
String name = namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
requireTypes.add(name);
}
}
return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).build();
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method generateOperationCallableMethod.
public StaticLangApiMethodView generateOperationCallableMethod(MethodContext context) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
setCommonFields(context, methodViewBuilder);
methodViewBuilder.name(namer.getOperationCallableMethodName(method));
methodViewBuilder.exampleName(context.getNamer().getOperationCallableMethodExampleName(method));
setCallableMethodFields(context, namer.getOperationCallableName(method), methodViewBuilder);
TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType();
methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
return methodViewBuilder.type(ClientMethodType.OperationCallableMethod).build();
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method generateAsyncOperationFlattenedMethod.
public StaticLangApiMethodView generateAsyncOperationFlattenedMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, ClientMethodType type, boolean requiresOperationMethod) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
setCommonFields(context, methodViewBuilder);
methodViewBuilder.name(namer.getAsyncApiMethodName(context.getMethodModel(), context.getMethodConfig().getVisibility()));
methodViewBuilder.exampleName(namer.getAsyncApiMethodExampleName(method));
methodViewBuilder.callableName(namer.getCallableName(method));
setFlattenedMethodFields(context, additionalParams, Synchronicity.Async, methodViewBuilder);
if (requiresOperationMethod) {
methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
}
TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType();
methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
return methodViewBuilder.type(type).build();
}
Aggregations