use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method generatePagedFlattenedMethod.
private StaticLangApiMethodSnippetView generatePagedFlattenedMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
StaticLangApiMethodView method = apiMethodTransformer.generatePagedFlattenedMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
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() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
// certain string until all of the types have been disambiguated.
for (int i = 0; i < 2; ++i) {
testCaseViews = ImmutableList.builder();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
}
return testCaseViews.build();
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createUnitTestCaseInitCodeContext.
private InitCodeContext createUnitTestCaseInitCodeContext(GapicInterfaceContext context, MethodModel method) {
MethodContext requestMethodContext = context.asRequestMethodContext(method);
MethodContext dynamicMethodContext = context.asDynamicMethodContext(method);
MethodConfig methodConfig = requestMethodContext.getMethodConfig();
Iterable<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();
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class DynamicLangApiMethodTransformer method removePageTokenFieldConfig.
private Iterable<FieldConfig> removePageTokenFieldConfig(GapicMethodContext context, Iterable<FieldConfig> fieldConfigs) {
MethodConfig methodConfig = context.getMethodConfig();
if (methodConfig == null || !methodConfig.isPageStreaming()) {
return fieldConfigs;
}
final FieldModel requestTokenField = methodConfig.getPageStreaming().getRequestTokenField();
return Iterables.filter(fieldConfigs, new Predicate<FieldConfig>() {
@Override
public boolean apply(FieldConfig fieldConfig) {
return !fieldConfig.getField().equals(requestTokenField);
}
});
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class InitCodeTransformer method generateRequestAssertViews.
/**
* Generates assert views for the test of the tested method and its fields.
*/
List<ClientTestAssertView> generateRequestAssertViews(MethodContext methodContext, InitCodeContext initContext) {
InitCodeNode rootNode = InitCodeNode.createTree(InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).initFields(initContext.initFields()).initValueConfigMap(createCollectionMap(methodContext)).suggestedName(Name.from("request")).fieldConfigMap(initContext.fieldConfigMap()).build());
List<ClientTestAssertView> assertViews = new ArrayList<>();
SurfaceNamer namer = methodContext.getNamer();
// Add request fields checking
for (InitCodeNode fieldItemTree : rootNode.getChildren().values()) {
FieldConfig fieldConfig = fieldItemTree.getFieldConfig();
String getterMethod = namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), fieldConfig);
String expectedValueIdentifier = getVariableName(methodContext, fieldItemTree);
String expectedTransformFunction = null;
String actualTransformFunction = null;
if (methodContext.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
if (fieldConfig.requiresParamTransformationFromAny()) {
expectedTransformFunction = namer.getToStringMethod();
actualTransformFunction = namer.getToStringMethod();
} else if (fieldConfig.requiresParamTransformation()) {
if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
expectedTransformFunction = namer.getToStringMethod();
} else {
expectedTransformFunction = namer.getResourceOneofCreateMethod(methodContext.getTypeTable(), fieldConfig);
}
} else if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
if (fieldConfig.getField().isRepeated()) {
actualTransformFunction = namer.getResourceTypeParseListMethodName(methodContext.getTypeTable(), fieldConfig);
} else if (fieldConfig.getResourceNameConfig().getResourceNameType() == ResourceNameType.ONEOF) {
actualTransformFunction = namer.getResourceTypeParentParseMethod(methodContext.getTypeTable(), fieldConfig);
} else {
actualTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), fieldConfig);
}
}
}
boolean isMap = fieldConfig.getField().isMap();
boolean isArray = fieldConfig.getField().isRepeated() && !isMap;
String enumTypeName = null;
TypeModel fieldType = fieldItemTree.getType();
if (fieldType.isEnum() && !fieldType.isRepeated()) {
enumTypeName = methodContext.getTypeTable().getNicknameFor(fieldType);
}
String messageTypeName = null;
if (fieldType.isMessage()) {
messageTypeName = methodContext.getTypeTable().getFullNameForMessageType(fieldType);
}
assertViews.add(createAssertView(expectedValueIdentifier, expectedTransformFunction, actualTransformFunction, isMap, isArray, getterMethod, enumTypeName, messageTypeName));
}
return assertViews;
}
Aggregations