Method method = methodEntry.getKey(); GapicMethodConfig methodConfig = GapicMethodConfig.createMethodConfig( diagCollector, language,
private boolean hasUnaryStreaming(GapicInterfaceConfig interfaceConfig) { return interfaceConfig .getMethodConfigs() .stream() .anyMatch( method -> method.isGrpcStreaming() && method.getGrpcStreaming().getType() == GrpcStreamingConfig.GrpcStreamingType.ServerStreaming); }
@Override public boolean hasGrpcStreamingMethods(GrpcStreamingConfig.GrpcStreamingType streamingType) { for (GapicMethodConfig methodConfig : getMethodConfigs()) { if (methodConfig.isGrpcStreaming() && methodConfig.getGrpcStreamingType() == streamingType) { return true; } } return false; }
private void addMethodImports(GapicMethodContext context) { ModelTypeTable typeTable = context.getTypeTable(); GapicMethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isLongRunningOperation()) { typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType()); typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType()); } typeTable.getAndSaveNicknameFor(context.getMethod().getInputType()); addFieldsImports(typeTable, methodConfig.getRequiredFields()); addFieldsImports(typeTable, methodConfig.getOptionalFields()); }
if (isGrpcStreamingMethod(methodModel)) { if (PageStreamingConfigProto.getDefaultInstance() .equals(methodConfigProto.getGrpcStreaming())) { defaultResourceNameTreatment(methodConfigProto, method, protoParser, defaultPackageName); createFieldNameConfigs( diagCollector, messageConfigs, fieldNamePatterns, resourceNameConfigs, getRequiredFields(diagCollector, methodModel, requiredFields)); createFieldNameConfigs( diagCollector, messageConfigs, fieldNamePatterns, resourceNameConfigs, getOptionalFields(methodModel, methodConfigProto.getRequiredFieldsList())); if (diagCollector.getErrorCount() > 0) { return null; findHeaderRequestParams(methodConfigProto, method, protoParser);
apiMethod.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility())); apiMethod.requestVariableName(namer.getRequestVariableName(method)); apiMethod.requestTypeName( apiMethod.key(namer.getMethodKey(method)); apiMethod.grpcMethodName(namer.getGrpcMethodName(method)); apiMethod.rerouteToGrpcInterface(context.getMethodConfig().getRerouteToGrpcInterface()); apiMethod.stubName(namer.getStubName(context.getTargetInterface())); removePageTokenFieldConfig(context, context.getMethodConfig().getOptionalFieldConfigs()); List<RequestObjectParamView> requiredParams = generateRequestObjectParams(context, context.getMethodConfig().getRequiredFieldConfigs()); List<RequestObjectParamView> optionalParams = generateRequestObjectParams(context, context.getMethodConfig().getOptionalFieldConfigs()); List<RequestObjectParamView> optionalParamsNoPageToken = generateRequestObjectParams(context, filteredFieldConfigs); GrpcStreamingType grpcStreamingType = context.getMethodConfig().getGrpcStreamingType(); apiMethod.grpcStreamingType(grpcStreamingType); apiMethod.isSingularRequestMethod( apiMethod.oneofParams(context.getMethodConfig().getOneofNames(namer)); apiMethod.headerRequestParams( headerRequestParamTransformer.generateHeaderRequestParams(context)); context, initContext, context.getMethodConfig().getRequiredFieldConfigs(), initCodeOutputType,
GapicMethodContext methodContext = context.asRequestMethodContext(method); if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) { if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) { initCodeOutputType = InitCodeOutputType.SingleObject; if (methodContext.getMethodConfig().isLongRunningOperation()) { clientMethodType = ClientMethodType.LongRunningOptionalArrayMethod; } else if (methodContext.getMethodConfig().isPageStreaming()) { clientMethodType = ClientMethodType.PagedOptionalArrayMethod; methodContext.getMethodConfig().getRequiredFieldConfigs(); InitCodeContext initCodeContext = InitCodeContext.newBuilder() .initObjectType(methodContext.getMethodModel().getInputType()) .suggestedName(Name.from("request")) .initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()) .initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)) .initFields(FieldConfig.toFieldTypeIterable(fieldConfigs))
boolean packageHasMultipleServices) { OptionalArrayMethodView methodView; if (methodContext.getMethodConfig().isPageStreaming()) { methodView = clientMethodTransformer.generatePagedStreamingMethod( packageHasMultipleServices, Arrays.asList(CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPaged)); } else if (methodContext.getMethodConfig().isLongRunningOperation()) { methodView = clientMethodTransformer.generateLongRunningMethod( } else { List<CallingForm> callingForms; GrpcStreamingType streamingType = methodContext.getMethodConfig().getGrpcStreamingType(); switch (streamingType) { case BidiStreaming:
private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodConfig methodConfig) { String returnTypeDoc = ""; if (methodConfig.isPageStreaming()) { returnTypeDoc = "Array of "; FieldModel resourcesType = methodConfig.getPageStreaming().getResourcesField(); if (resourcesType.isMessage()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType()); } else if (resourcesType.isEnum()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType()); } else { // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter. returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase(); } } else if (methodConfig.isLongRunningOperation()) { returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object"; } else { returnTypeDoc = getTypeNameDoc(typeTable, ProtoTypeRef.create(methodConfig.getMethod().getOutputType())); } return returnTypeDoc; }
private List<String> returnCallbackDocLines( ImportTypeTable typeTable, GapicMethodConfig methodConfig) { String returnTypeDoc = returnTypeDoc(typeTable, methodConfig); Method method = methodConfig.getMethod(); MethodModel methodModel = methodConfig.getMethodModel(); String classInfo = getParamTypeName(typeTable, methodModel.getOutputType()); String callbackType; if (isProtobufEmpty(method.getOutputMessage())) { callbackType = "function(?Error)"; } else if (methodConfig.isPageStreaming()) { callbackType = String.format("function(?Error, ?Array, ?Object, ?%s)", classInfo); } else { if (!isProtobufEmpty(method.getOutputMessage())) { callbackLines.add("", " The second parameter to the callback is " + returnTypeDoc + "."); if (methodConfig.isPageStreaming()) { callbackLines.add( "",
for (MethodModel method : context.getSupportedMethods()) { GapicMethodContext methodContext = context.asRequestMethodContext(method); if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) { methodContext.getMethodConfig().getRequiredFieldConfigs(); InitCodeContext initCodeContext = InitCodeContext.newBuilder() .initObjectType(methodContext.getMethodModel().getInputType()) .suggestedName(Name.from("request")) .initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()) .initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)) .initFields(FieldConfig.toFieldTypeIterable(fieldConfigs))
GapicMethodConfig.defaultResourceNameTreatment( noConfig, createShelvesMethod, protoParser, DEFAULT_PACKAGE); assertThat(noTreatment).isEqualTo(ResourceNameTreatment.NONE); GapicMethodConfig.defaultResourceNameTreatment( staticTypesMethodConfig, createShelvesMethod, protoParser, DEFAULT_PACKAGE); assertThat(resourceNameTreatment).isEqualTo(ResourceNameTreatment.STATIC_TYPES); GapicMethodConfig.defaultResourceNameTreatment( noConfig, insertBook, protoParser, DEFAULT_PACKAGE); assertThat(noConfigWithAnnotatedResourceReferenceTreatment)
public List<HeaderRequestParamView> generateHeaderRequestParams(MethodContext context) { if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) { return ImmutableList.of(); } GapicMethodConfig methodConfig = (GapicMethodConfig) context.getMethodConfig(); Method method = methodConfig.getMethod(); SurfaceNamer namer = context.getNamer(); if (method.getInputType() == null || !method.getInputType().isMessage()) { return ImmutableList.of(); } ImmutableList.Builder<HeaderRequestParamView> headerRequestParams = ImmutableList.builder(); MessageType inputMessageType = method.getInputType().getMessageType(); for (String headerRequestParam : methodConfig.getHeaderRequestParams()) { headerRequestParams.add( generateHeaderRequestParam(headerRequestParam, inputMessageType, namer)); } return headerRequestParams.build(); }
/** Returns a list of methods for this interface that have method configs. Memoize the result. */ @Override public List<MethodModel> getInterfaceConfigMethods() { if (interfaceMethods != null) { return interfaceMethods; } ImmutableList.Builder<MethodModel> methodBuilder = ImmutableList.builder(); for (MethodConfig methodConfig : getInterfaceConfig().getMethodConfigs()) { methodBuilder.add(new ProtoMethodModel(((GapicMethodConfig) methodConfig).getMethod())); } interfaceMethods = methodBuilder.build(); return interfaceMethods; }
@Override public MethodModel getMethodModel() { return getMethodConfig().getMethodModel(); }
private List<GrpcStreamingDetailView> createGrpcStreamingDescriptors( GapicInterfaceContext context) { List<GrpcStreamingDetailView> result = new ArrayList<>(); for (MethodModel method : context.getGrpcStreamingMethods()) { GrpcStreamingConfig grpcStreamingConfig = context.asDynamicMethodContext(method).getMethodConfig().getGrpcStreaming(); String resourcesFieldGetFunction = null; if (grpcStreamingConfig.hasResourceField()) { resourcesFieldGetFunction = context.getNamer().getFieldGetFunctionName(grpcStreamingConfig.getResourcesField()); } result.add( GrpcStreamingDetailView.newBuilder() .methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)) .transportMethodName(context.getNamer().getGrpcMethodName(method)) .grpcStreamingType(grpcStreamingConfig.getType()) .grpcResourcesField(resourcesFieldGetFunction) .build()); } return result; }
private List<LongRunningOperationDetailView> createLongRunningDescriptors( GapicInterfaceContext context) { List<LongRunningOperationDetailView> result = new ArrayList<>(); for (MethodModel method : context.getLongRunningMethods()) { GapicMethodContext methodContext = context.asDynamicMethodContext(method); LongRunningConfig lroConfig = methodContext.getMethodConfig().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)) .implementsCancel(true) .implementsDelete(true) .initialPollDelay(lroConfig.getInitialPollDelay().toMillis()) .pollDelayMultiplier(lroConfig.getPollDelayMultiplier()) .maxPollDelay(lroConfig.getMaxPollDelay().toMillis()) .totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()) .build()); } return result; }
private boolean hasRequestHeaderParams(GapicInterfaceContext context) { return context .getInterfaceConfig() .getMethodConfigs() .stream() .anyMatch(config -> config.getHeaderRequestParams().iterator().hasNext()); }
private void addMethodImports(GapicMethodContext context) { ModelTypeTable typeTable = context.getTypeTable(); GapicMethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isLongRunningOperation()) { typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType()); typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType()); } typeTable.getAndSaveNicknameFor(context.getMethod().getInputType()); addFieldsImports(typeTable, methodConfig.getRequiredFields()); addFieldsImports(typeTable, methodConfig.getOptionalFields()); }
private OptionalArrayMethodView generateOneApiMethod( GapicMethodContext methodContext, InitCodeContext initContext) { OptionalArrayMethodView methodView = null; if (methodContext.getMethodConfig().isPageStreaming()) { methodView = clientMethodTransformer.generatePagedStreamingMethod( false, Arrays.asList(CallingForm.RequestPaged, CallingForm.RequestPagedAll)); } else if (methodContext.getMethodConfig().isLongRunningOperation()) { methodView = clientMethodTransformer.generateLongRunningMethod( } else { List<CallingForm> callingForms; GrpcStreamingType streamingType = methodContext.getMethodConfig().getGrpcStreamingType(); switch (streamingType) { case BidiStreaming: