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(initContext.cloneWithEmptySymbolTable());
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, fieldConfig);
} else {
actualTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), fieldConfig);
}
}
}
boolean isMap = fieldConfig.getField().isMap();
boolean isArray = fieldConfig.getField().isRepeated() && !isMap;
boolean isFloatingPointNumber = fieldConfig.getField().getType().isFloatType() || fieldConfig.getField().getType().isDoubleType();
TypeModel fieldType = fieldItemTree.getType();
String messageTypeName = null;
if (fieldType.isMessage()) {
messageTypeName = methodContext.getTypeTable().getFullNameForMessageType(fieldType);
}
assertViews.add(createAssertView(expectedValueIdentifier, expectedTransformFunction, actualTransformFunction, isMap, isArray, isFloatingPointNumber, getterMethod, messageTypeName));
}
return assertViews;
}
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 NodeJSGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
Collection<FieldConfig> fieldConfigs = 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)).outputType(InitCodeOutputType.SingleObject).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, getMethodType(methodContext)));
}
return testCaseViews;
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
initCodeOutputType = InitCodeOutputType.SingleObject;
}
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.isLongRunningMethodContext()) {
clientMethodType = ClientMethodType.LongRunningOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Collection<FieldConfig> fieldConfigs = 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)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
return testCaseViews;
}
use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.
the class JavaSurfaceTransformer method getIterateMethods.
private List<PagedResponseIterateMethodView> getIterateMethods(MethodContext context) {
SurfaceNamer namer = context.getNamer();
List<PagedResponseIterateMethodView> iterateMethods = new ArrayList<>();
FieldConfig resourceFieldConfig = context.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
if (context.getFeatureConfig().useResourceNameFormatOption(resourceFieldConfig)) {
String resourceTypeName = namer.getAndSaveElementResourceTypeName(context.getTypeTable(), resourceFieldConfig);
String resourceTypeIterateMethodName = namer.getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig);
String resourceTypeGetValuesMethodName = namer.getPageGetValuesMethod(context.getFeatureConfig(), resourceFieldConfig);
String parseMethodName = namer.getResourceTypeParseMethodName(context.getTypeTable(), resourceFieldConfig);
PagedResponseIterateMethodView.Builder iterateMethod = PagedResponseIterateMethodView.newBuilder().overloadResourceTypeName(resourceTypeName).overloadResourceTypeParseFunctionName(parseMethodName).overloadResourceTypeIterateMethodName(resourceTypeIterateMethodName).overloadResourceTypeGetValuesMethodName(resourceTypeGetValuesMethodName).iterateMethodName(namer.getPagedResponseIterateMethod()).getValuesMethodName(namer.getPageGetValuesMethod());
iterateMethods.add(iterateMethod.build());
}
return iterateMethods;
}
Aggregations