use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method setFlattenedMethodFields.
private void setFlattenedMethodFields(MethodContext context, List<ParamWithSimpleDoc> additionalParams, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
Iterable<FieldConfig> fieldConfigs = context.getFlatteningConfig().getFlattenedFieldConfigs().values();
methodViewBuilder.initCode(initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, fieldConfigs, InitCodeOutputType.FieldList)));
methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(getMethodParamDocs(context, fieldConfigs, additionalParams)).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, synchronicity)).build());
List<RequestObjectParamView> params = new ArrayList<>();
for (FieldConfig fieldConfig : fieldConfigs) {
params.add(resourceObjectTransformer.generateRequestObjectParam(context, fieldConfig));
}
methodViewBuilder.forwardingMethodParams(params);
List<RequestObjectParamView> nonforwardingParams = new ArrayList<>(params);
nonforwardingParams.addAll(ParamWithSimpleDoc.asRequestObjectParamViews(additionalParams));
methodViewBuilder.methodParams(nonforwardingParams);
methodViewBuilder.requestObjectParams(params);
methodViewBuilder.pathTemplateChecks(generatePathTemplateChecks(context, fieldConfigs));
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class TestCaseTransformer method createSmokeTestInitContext.
public InitCodeContext createSmokeTestInitContext(MethodContext context) {
SmokeTestConfig testConfig = context.getInterfaceConfig().getSmokeTestConfig();
InitCodeContext.InitCodeOutputType outputType;
ImmutableMap<String, FieldConfig> fieldConfigMap;
if (context.isFlattenedMethodContext()) {
outputType = InitCodeContext.InitCodeOutputType.FieldList;
fieldConfigMap = FieldConfig.toFieldConfigMap(context.getFlatteningConfig().getFlattenedFieldConfigs().values());
} else {
outputType = InitCodeContext.InitCodeOutputType.SingleObject;
fieldConfigMap = FieldConfig.toFieldConfigMap(context.getMethodConfig().getRequiredFieldConfigs());
}
// Store project ID variable name into the symbol table since it is used
// by the execute method as a parameter.
SymbolTable table = new SymbolTable();
table.getNewSymbol(Name.from(InitFieldConfig.PROJECT_ID_VARIABLE_NAME));
InitCodeContext.Builder contextBuilder = InitCodeContext.newBuilder().initObjectType(testConfig.getMethod().getInputType()).suggestedName(Name.from("request")).outputType(outputType).initValueConfigMap(InitCodeTransformer.createCollectionMap(context)).initFieldConfigStrings(testConfig.getInitFieldConfigStrings()).symbolTable(table).fieldConfigMap(fieldConfigMap);
if (context.isFlattenedMethodContext()) {
contextBuilder.initFields(context.getFlatteningConfig().getFlattenedFields());
}
return contextBuilder.build();
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class TestCaseTransformer method createPageStreamingResponseViews.
private List<PageStreamingResponseView> createPageStreamingResponseViews(MethodContext methodContext) {
MethodConfig methodConfig = methodContext.getMethodConfig();
SurfaceNamer namer = methodContext.getNamer();
List<PageStreamingResponseView> pageStreamingResponseViews = new ArrayList<>();
if (!methodConfig.isPageStreaming()) {
return pageStreamingResponseViews;
}
FieldConfig resourcesFieldConfig = methodConfig.getPageStreaming().getResourcesFieldConfig();
FieldModel resourcesField = resourcesFieldConfig.getField();
String resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
// Construct the list of function calls needed to retrieve paged resource from response object.
ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
}
pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod()).resourcesVarName(namer.localVarName(Name.from("resources"))).build());
if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) {
resourceTypeName = methodContext.getNamer().getAndSaveElementResourceTypeName(methodContext.getTypeTable(), resourcesFieldConfig);
resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig));
}
String expectedTransformFunction = null;
if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) {
expectedTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), resourcesFieldConfig);
}
pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod(methodContext.getFeatureConfig(), resourcesFieldConfig)).expectedValueTransformFunction(expectedTransformFunction).resourcesVarName(namer.localVarName(Name.from("resource_names"))).build());
}
return pageStreamingResponseViews;
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class CSharpGapicSmokeTestTransformer method createSmokeTestCaseApiMethodView.
private StaticLangApiMethodView createSmokeTestCaseApiMethodView(GapicInterfaceContext context, MethodContext methodContext) {
SurfaceNamer namer = context.getNamer();
MethodConfig methodConfig = methodContext.getMethodConfig();
StaticLangApiMethodView.Builder apiMethodView;
if (methodConfig.isPageStreaming()) {
apiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext).toBuilder();
FieldConfig resourceFieldConfig = methodContext.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
apiMethodView.responseTypeName(callerResponseTypeName);
} else if (methodConfig.isLongRunningOperation()) {
ArrayList<ParamWithSimpleDoc> emptyParams = new ArrayList<ParamWithSimpleDoc>();
apiMethodView = apiMethodTransformer.generateOperationFlattenedMethod(methodContext, emptyParams).toBuilder();
} else {
apiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext).toBuilder();
}
InitCodeTransformer initCodeTransformer = new InitCodeTransformer();
InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
apiMethodView.initCode(initCodeView);
return apiMethodView.build();
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method generatePagedFlattenedAsyncMethod.
private StaticLangApiMethodSnippetView generatePagedFlattenedAsyncMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
StaticLangApiMethodView method = apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
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() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
Aggregations