public ImmutableList<FieldModel> getRequiredFields() { return getRequiredFieldConfigs() .stream() .map(FieldConfig::getField) .collect(ImmutableList.toImmutableList()); }
private boolean hasParams(MethodConfig methodConfig) { if (!Iterables.isEmpty(methodConfig.getRequiredFieldConfigs())) { return true; } int optionalParamCount = Iterables.size(methodConfig.getOptionalFieldConfigs()); // Must have at least one parameter that is not the page token parameter. return optionalParamCount > (methodConfig.getPageStreaming() == null ? 0 : 1); }
/** Determines whether a field is required */ private static boolean isRequired(FieldConfig fieldConfig, MethodContext context) { return fieldConfig != null && context .getMethodConfig() .getRequiredFieldConfigs() .stream() .anyMatch( fc -> fc.getField().getSimpleName().equals(fieldConfig.getField().getSimpleName())); }
private TestCaseView createRequestObjectTestCase( GapicMethodContext requestContext, MethodConfig methodConfig, SymbolTable testNameTable, Synchronicity synchronicity) { InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext( requestContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator); return testCaseTransformer.createTestCaseView( requestContext, testNameTable, initCodeContext, synchronicity == Synchronicity.Sync ? ClientMethodType.RequestObjectMethod : ClientMethodType.AsyncRequestObjectCallSettingsMethod, synchronicity, null, null); }
private ParamDocView generateRequestObjectParamDoc(GapicMethodContext context) { MethodConfig methodConfig = context.getMethodConfig(); SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder(); paramDoc.lines(ImmutableList.of("The request object that will be sent.")); String paramName = context.getNamer().localVarName(Name.from("request")); Iterable<FieldModel> optionalParams = removePageTokenFromFields(methodConfig); if (!methodConfig.getRequiredFieldConfigs().iterator().hasNext() && !optionalParams.iterator().hasNext()) { paramName = String.format("[%s]", paramName); } paramDoc.paramName(paramName); paramDoc.typeName("Object"); return paramDoc.build(); }
context.getNamer().publicClassName(DiscoGapicParser.getResourceNameName(nameConfig))); for (FieldConfig fieldConfig : context.getMethodConfig().getRequiredFieldConfigs()) { if (fieldConfig.getResourceNameConfig() != null && fieldConfig.getResourceNameConfig().equals(nameConfig)) {
methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, initCodeContext ->
private StaticLangApiMethodSnippetView generateOperationRequestAsyncMethod( MethodContext methodContext) { SurfaceNamer namer = methodContext.getNamer(); StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateAsyncOperationRequestObjectMethod( methodContext, Collections.<ParamWithSimpleDoc>emptyList(), true), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.LongRunningRequestAsync); String callerResponseTypeName = method.operationMethod().clientReturnTypeName(); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private StaticLangApiMethodSnippetView generateGrpcStreamingRequestMethod( MethodContext methodContext) { SurfaceNamer namer = methodContext.getNamer(); StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(methodContext), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestStreamingServer); String callerResponseTypeName = method.name() + "Stream"; return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name()) .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private StaticLangApiMethodSnippetView generateOperationRequestMethod( MethodContext methodContext) { SurfaceNamer namer = methodContext.getNamer(); StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateOperationRequestObjectMethod(methodContext), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.LongRunningRequest); String callerResponseTypeName = method.operationMethod().clientReturnTypeName(); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, initCodeContext ->
private StaticLangApiMethodSnippetView generateRequestAsyncMethod(MethodContext methodContext) { SurfaceNamer namer = methodContext.getNamer(); StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateRequestObjectAsyncMethod(methodContext), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestAsync); String callerResponseTypeName = methodContext .getTypeTable() .getAndSaveNicknameFor(namer.getStaticLangCallerAsyncReturnTypeName(methodContext)); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private StaticLangApiMethodSnippetView generateRequestMethod(MethodContext methodContext) { SurfaceNamer namer = methodContext.getNamer(); StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateRequestObjectMethod(methodContext), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.Request); String callerResponseTypeName = methodContext .getTypeTable() .getAndSaveNicknameFor(namer.getStaticLangCallerAsyncReturnTypeName(methodContext)); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private InitCodeContext createUnitTestCaseInitCodeContext( GapicInterfaceContext context, MethodModel method) { MethodContext requestMethodContext = context.asRequestMethodContext(method); MethodContext dynamicMethodContext = context.asDynamicMethodContext(method); MethodConfig methodConfig = requestMethodContext.getMethodConfig(); Collection<FieldConfig> fieldConfigs = methodConfig.getRequiredFieldConfigs(); InitCodeOutputType outputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList; return InitCodeContext.newBuilder() .initObjectType(method.getInputType()) .suggestedName(Name.from("request")) .initFieldConfigStrings(methodConfig.getSampleCodeInitFields()) .initValueConfigMap(InitCodeTransformer.createCollectionMap(dynamicMethodContext)) .initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)) .outputType(outputType) .fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)) .build(); }
private StaticLangApiMethodSnippetView generatePagedRequestMethod(MethodContext methodContext) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generatePagedRequestObjectMethod( methodContext, csharpCommonTransformer.pagedMethodAdditionalParams()), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestPaged); SurfaceNamer namer = methodContext.getNamer(); PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private StaticLangApiMethodSnippetView generatePagedRequestAsyncMethod( MethodContext methodContext) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generatePagedRequestObjectAsyncMethod( methodContext, csharpCommonTransformer.pagedMethodAdditionalParams()), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestAsyncPaged); SurfaceNamer namer = methodContext.getNamer(); PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); String callerResponseTypeName = namer.getAndSaveCallerAsyncPagedResponseTypeName(methodContext, resourceFieldConfig); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
outputType = InitCodeContext.InitCodeOutputType.SingleObject; fieldConfigMap = FieldConfig.toFieldConfigMap(context.getMethodConfig().getRequiredFieldConfigs());