Search in sources :

Example 36 with FieldModel

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();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 37 with FieldModel

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();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 38 with FieldModel

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();
}
Also used : DynamicLangDefaultableParamView(com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView) ImmutableList(com.google.common.collect.ImmutableList) FieldModel(com.google.api.codegen.config.FieldModel)

Example 39 with FieldModel

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;
}
Also used : ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Example 40 with FieldModel

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;
}
Also used : ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

FieldModel (com.google.api.codegen.config.FieldModel)44 MethodConfig (com.google.api.codegen.config.MethodConfig)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)11 FieldConfig (com.google.api.codegen.config.FieldConfig)9 MethodModel (com.google.api.codegen.config.MethodModel)8 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)7 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)6 BatchingConfig (com.google.api.codegen.config.BatchingConfig)4 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)4 DynamicLangDefaultableParamView (com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView)4 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 Name (com.google.api.codegen.util.Name)3 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)2 GenericFieldSelector (com.google.api.codegen.config.GenericFieldSelector)2 Schema (com.google.api.codegen.discovery.Schema)2 SymbolTable (com.google.api.codegen.util.SymbolTable)2 TypeName (com.google.api.codegen.util.TypeName)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2