Search in sources :

Example 11 with TypeModel

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);
}
Also used : Scanner(com.google.api.codegen.util.Scanner) OutputView(com.google.api.codegen.viewmodel.OutputView) TypeModel(com.google.api.codegen.config.TypeModel) FieldModel(com.google.api.codegen.config.FieldModel) Test(org.junit.Test)

Example 12 with 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);
}
Also used : Scanner(com.google.api.codegen.util.Scanner) OutputView(com.google.api.codegen.viewmodel.OutputView) TypeModel(com.google.api.codegen.config.TypeModel) Test(org.junit.Test)

Example 13 with 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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeModel(com.google.api.codegen.config.TypeModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) HashSet(java.util.HashSet)

Example 14 with TypeModel

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();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Example 15 with TypeModel

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();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Aggregations

TypeModel (com.google.api.codegen.config.TypeModel)32 MethodModel (com.google.api.codegen.config.MethodModel)12 Test (org.junit.Test)12 Scanner (com.google.api.codegen.util.Scanner)10 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)10 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)10 OutputView (com.google.api.codegen.viewmodel.OutputView)8 FieldModel (com.google.api.codegen.config.FieldModel)7 ImmutableList (com.google.common.collect.ImmutableList)4 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)3 ArrayList (java.util.ArrayList)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2 OutputTransformer (com.google.api.codegen.transformer.OutputTransformer)2 LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HashSet (java.util.HashSet)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1