Search in sources :

Example 41 with FieldModel

use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.

the class MethodTransformer method generatePageStreamingRequest.

private PageStreamingRequestView generatePageStreamingRequest(MethodModel method) {
    PageStreamingRequestView.Builder requestBuilder = PageStreamingRequestView.newBuilder();
    for (FieldModel field : method.getInputFields()) {
        String fieldName = field.getSimpleName();
        if (fieldName.equals(helperTransformer.getPagingParameters().getNameForPageToken())) {
            requestBuilder.tokenField(fieldName);
        } else if (fieldName.equals(helperTransformer.getPagingParameters().getNameForPageSize())) {
            requestBuilder.pageSizeField(fieldName);
        }
    }
    PageStreamingRequestView request = requestBuilder.build();
    return request.tokenField() == null && request.pageSizeField() == null ? null : request;
}
Also used : PageStreamingRequestView(com.google.api.codegen.configgen.viewmodel.PageStreamingRequestView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 42 with FieldModel

use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.

the class MethodTransformer method generateField.

private void generateField(MethodModel method, MethodView.Builder methodView) {
    List<String> parameterList = new ArrayList<>();
    List<FieldModel> fieldList = new ArrayList<>();
    Iterable<? extends FieldModel> inputFields = method.getInputFields();
    for (FieldModel field : inputFields) {
        String fieldName = field.getSimpleName();
        if (field.getOneof() == null && !helperTransformer.getPagingParameters().getIgnoredParameters().contains(fieldName)) {
            parameterList.add(fieldName);
            fieldList.add(field);
        }
    }
    List<String> parameters = filteredInputFields(method, fieldList);
    if (parameters.size() > 0 && parameters.size() <= FLATTENING_THRESHOLD) {
        methodView.flattening(generateFlattening(parameters));
    }
    methodView.requiredFields(parameters);
    // use all fields for the following check; if there are ignored fields for flattening
    // purposes, the caller still needs a way to set them (by using the request object method).
    methodView.requestObjectMethod((Iterators.size(inputFields.iterator()) > REQUEST_OBJECT_METHOD_THRESHOLD || Iterators.size(inputFields.iterator()) != parameterList.size()) && !method.getRequestStreaming());
    methodView.resourceNameTreatment(helperTransformer.getResourceNameTreatment(method));
}
Also used : ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel)

Example 43 with FieldModel

use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.

the class PythonApiMethodParamTransformer method generateMethodParams.

@Override
public List<DynamicLangDefaultableParamView> generateMethodParams(GapicMethodContext context) {
    ImmutableList.Builder<DynamicLangDefaultableParamView> methodParams = ImmutableList.builder();
    methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("self").defaultValue("").build());
    if (context.getMethod().getRequestStreaming()) {
        methodParams.add(DynamicLangDefaultableParamView.newBuilder().name(context.getNamer().getRequestVariableName(context.getMethodModel())).defaultValue("").build());
    } else {
        for (FieldModel field : context.getMethodConfig().getRequiredFields()) {
            DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
            param.name(context.getNamer().getVariableName(field));
            param.defaultValue("");
            methodParams.add(param.build());
        }
        for (FieldModel field : context.getMethodConfig().getOptionalFields()) {
            if (isRequestTokenParam(context.getMethodConfig(), field)) {
                continue;
            }
            DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
            param.name(context.getNamer().getVariableName(field));
            param.defaultValue("None");
            methodParams.add(param.build());
        }
    }
    methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("retry").defaultValue("google.api_core.gapic_v1.method.DEFAULT").build());
    methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("timeout").defaultValue("google.api_core.gapic_v1.method.DEFAULT").build());
    methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("metadata").defaultValue("None").build());
    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 44 with FieldModel

use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.

the class PythonApiMethodParamTransformer method generateMethodParamDocs.

private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
    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();
        paramDoc.paramName(namer.getVariableName(field));
        paramDoc.typeName(namer.getParamTypeName(context.getTypeTable(), field.getType()));
        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(namer.getDocLines(field));
            boolean isMessageField = field.isMessage() && !field.isMap();
            boolean isMapContainingMessage = field.isMap() && field.getMapValueField().isMessage();
            if (isMessageField || isMapContainingMessage) {
                String messageType;
                if (isMapContainingMessage) {
                    messageType = context.getTypeTable().getFullNameForElementType(field.getMapValueField());
                } else {
                    messageType = context.getTypeTable().getFullNameForElementType(field);
                }
                docLines.add("If a dict is provided, it must be of the same form as the protobuf", String.format("message :class:`%s`", PythonDocstringUtil.napoleonType(messageType, namer.getVersionedDirectoryNamespace())));
            }
        }
        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)

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