Search in sources :

Example 66 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method generateFlattenedAsyncMethod.

// Used by: C#
public StaticLangApiMethodView generateFlattenedAsyncMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, ClientMethodType type, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getAsyncApiMethodName(method, context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getCallableMethodExampleName(method));
    methodViewBuilder.callableName(namer.getCallableName(method));
    setFlattenedMethodFields(context, additionalParams, Synchronicity.Async, methodViewBuilder, context.getCallingForms(), sampleContext);
    setStaticLangAsyncReturnTypeName(context, methodViewBuilder);
    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)

Example 67 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.

the class GoGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    MethodContext methodContext = context.asRequestMethodContext(method);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(namer.getSmokeTestClassName(context.getInterfaceConfig()));
    testClass.outputPath(context.getProductConfig().getPackageName() + File.separator + method.getSimpleName() + "_smoke_test.go");
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    // The shared code above add imports both for input and output.
    // Since we use short decls, we don't need to import anything for output.
    context.getImportTypeTable().getImports().clear();
    method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 68 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.

the class GoGapicSurfaceTestTransformer method createSmokeTestCaseApiMethodView.

private StaticLangApiMethodView createSmokeTestCaseApiMethodView(MethodContext methodContext) {
    StaticLangApiMethodView initialApiMethodView;
    if (methodContext.getMethodConfig().isPageStreaming()) {
        initialApiMethodView = apiMethodTransformer.generatePagedRequestObjectMethod(methodContext, null);
    } else {
        initialApiMethodView = apiMethodTransformer.generateRequestObjectMethod(methodContext, null);
    }
    StaticLangApiMethodView.Builder apiMethodView = initialApiMethodView.toBuilder();
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
    apiMethodView.initCode(initCodeView);
    return apiMethodView.build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 69 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.

the class JavaApiMethodTransformer method generateGrpcStreamingMethods.

private List<StaticLangApiMethodView> generateGrpcStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    List<CallingForm> callingForms;
    ImportTypeTable typeTable = interfaceContext.getImportTypeTable();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    switch(methodConfig.getGrpcStreamingType()) {
        case BidiStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingBidi);
            break;
        case ClientStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingClient);
            break;
        case ServerStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingServer);
            break;
        default:
            throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
    }
    apiMethods.add(generateCallableMethod(methodContext.withCallingForms(callingForms), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) CallingForm(com.google.api.codegen.viewmodel.CallingForm) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext)

Example 70 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.

the class JavaSurfaceTransformer method generateApiClass.

private StaticLangApiView generateApiClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addApiImports(context);
    List<StaticLangApiMethodView> methods = javaApiMethodTransformer.generateApiMethods(context);
    StaticLangApiView.Builder xapiClass = StaticLangApiView.newBuilder();
    ApiMethodView exampleApiMethod = getExampleApiMethod(methods);
    xapiClass.doc(serviceTransformer.generateServiceDoc(context, exampleApiMethod, productConfig));
    String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig());
    xapiClass.releaseLevelAnnotation(namer.getReleaseAnnotation(productConfig.getReleaseLevel()));
    xapiClass.name(name);
    xapiClass.settingsClassName(namer.getApiSettingsClassName(interfaceConfig));
    xapiClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xapiClass.stubSettingsClassName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
    xapiClass.apiCallableMembers(apiCallableTransformer.generateStaticLangApiCallables(context));
    xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    xapiClass.apiMethods(methods);
    xapiClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xapiClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
    xapiClass.pagedResponseViews(generatePagedResponseWrappers(context));
    return xapiClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Aggregations

StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)71 MethodModel (com.google.api.codegen.config.MethodModel)43 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)35 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)22 ArrayList (java.util.ArrayList)14 FieldConfig (com.google.api.codegen.config.FieldConfig)12 MethodConfig (com.google.api.codegen.config.MethodConfig)12 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)10 TypeModel (com.google.api.codegen.config.TypeModel)10 InterfaceContext (com.google.api.codegen.config.InterfaceContext)9 MethodContext (com.google.api.codegen.config.MethodContext)9 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)8 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)6 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)4 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)4 ViewModel (com.google.api.codegen.viewmodel.ViewModel)4 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)3 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)3 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)3 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)3