use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class NodeJSApiMethodParamTransformer method generateRequestObjectParamDoc.
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();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class NodeJSApiMethodParamTransformer method generateMethodParamDocs.
private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields, boolean isOptional) {
SurfaceNamer namer = context.getNamer();
MethodConfig methodConfig = context.getMethodConfig();
ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
for (FieldModel field : fields) {
if (isRequestTokenParam(methodConfig, field)) {
continue;
}
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
String paramName = "request." + namer.getVariableName(field);
if (isOptional) {
paramName = String.format("[%s]", paramName);
}
paramDoc.paramName(paramName);
String typeName = namer.getParamTypeName(context.getTypeTable(), field.getType());
paramDoc.typeName(typeName);
List<String> fieldDocLines = namer.getDocLines(field);
ImmutableList.Builder<String> docLines = ImmutableList.builder();
if (isPageSizeParam(methodConfig, field)) {
docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
} else {
docLines.addAll(fieldDocLines);
}
paramDoc.lines(docLines.build());
docs.add(paramDoc.build());
}
return docs.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class NodeJSApiMethodParamTransformer method generateDefaultableParams.
private List<DynamicLangDefaultableParamView> generateDefaultableParams(GapicMethodContext context) {
if (context.getMethodModel().getRequestStreaming()) {
return ImmutableList.of();
}
ImmutableList.Builder<DynamicLangDefaultableParamView> methodParams = ImmutableList.builder();
for (FieldModel field : context.getMethodConfig().getRequiredFields()) {
DynamicLangDefaultableParamView param = DynamicLangDefaultableParamView.newBuilder().name(context.getNamer().getVariableName(field)).defaultValue("").build();
methodParams.add(param);
}
return methodParams.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class NodeJSSurfaceNamer method returnTypeDoc.
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, new ProtoTypeRef(methodConfig.getMethod().getOutputType()));
}
return returnTypeDoc;
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class MethodTransformer method filteredInputFields.
/**
* Get the filtered input fields for a model, from a list of candidates.
*/
private List<String> filteredInputFields(MethodModel method, List<FieldModel> candidates) {
List<String> parameterNames = new ArrayList<>();
List<? extends FieldModel> parametersForResourceNameMethod = method.getInputFieldsForResourceNameMethod();
for (FieldModel field : candidates) {
if (parametersForResourceNameMethod.contains(field)) {
parameterNames.add(field.getNameAsParameter());
}
}
return parameterNames;
}
Aggregations