Search in sources :

Example 1 with ParamDocView

use of com.google.api.codegen.viewmodel.ParamDocView in project toolkit by googleapis.

the class GrpcElementDocTransformer method generateMessagePropertyDocs.

private List<ParamDocView> generateMessagePropertyDocs(ModelTypeTable typeTable, SurfaceNamer namer, Iterable<FieldModel> fields) {
    ImmutableList.Builder<ParamDocView> propertyDocs = ImmutableList.builder();
    for (FieldModel field : fields) {
        SimpleParamDocView.Builder doc = SimpleParamDocView.newBuilder();
        doc.paramName(namer.getFieldKey(field));
        doc.typeName(namer.getMessagePropertyTypeName(typeTable, field));
        doc.lines(namer.getDocLines(field));
        propertyDocs.add(doc.build());
    }
    return propertyDocs.build();
}
Also used : 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)

Example 2 with ParamDocView

use of com.google.api.codegen.viewmodel.ParamDocView in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method setRequestObjectMethodFields.

private void setRequestObjectMethodFields(MethodContext context, String callableMethodName, Synchronicity sync, List<ParamWithSimpleDoc> additionalParams, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    List<ParamDocView> paramDocs = new ArrayList<>();
    paramDocs.addAll(getRequestObjectParamDocs(context));
    paramDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParams));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(paramDocs).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, sync)).build());
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject));
    methodViewBuilder.initCode(initCode);
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    RequestObjectMethodDetailView.Builder detailBuilder = RequestObjectMethodDetailView.newBuilder();
    if (context.getMethodConfig().hasRequestObjectMethod()) {
        detailBuilder.accessModifier(context.getNamer().getVisiblityKeyword(context.getMethodConfig().getVisibility()));
    } else {
        detailBuilder.accessModifier(context.getNamer().getPrivateAccessModifier());
    }
    detailBuilder.callableMethodName(callableMethodName);
    methodViewBuilder.requestObjectMethod(detailBuilder.build());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) RequestObjectMethodDetailView(com.google.api.codegen.viewmodel.RequestObjectMethodDetailView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 3 with ParamDocView

use of com.google.api.codegen.viewmodel.ParamDocView in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method getMethodParamDocs.

private List<ParamDocView> getMethodParamDocs(MethodContext context, Iterable<FieldConfig> fieldConfigs, List<ParamWithSimpleDoc> additionalParamDocs) {
    MethodModel method = context.getMethodModel();
    List<ParamDocView> allDocs = new ArrayList<>();
    if (method.getRequestStreaming()) {
        allDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParamDocs));
        return allDocs;
    }
    for (FieldConfig fieldConfig : fieldConfigs) {
        FieldModel field = fieldConfig.getField();
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(context.getNamer().getVariableName(field));
        paramDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(field));
        List<String> docLines = null;
        MethodConfig methodConfig = context.getMethodConfig();
        if (methodConfig.isPageStreaming() && methodConfig.getPageStreaming().hasPageSizeField() && field.equals(methodConfig.getPageStreaming().getPageSizeField())) {
            docLines = Arrays.asList(new String[] { "The maximum number of resources contained in the underlying API", "response. The API may return fewer values in a page, even if", "there are additional values to be retrieved." });
        } else if (methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField())) {
            docLines = Arrays.asList(new String[] { "A page token is used to specify a page of values to be returned.", "If no page token is specified (the default), the first page", "of values will be returned. Any page token used here must have", "been generated by a previous call to the API." });
        } else {
            docLines = context.getNamer().getDocLines(field);
        }
        paramDoc.lines(docLines);
        allDocs.add(paramDoc.build());
    }
    allDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParamDocs));
    return allDocs;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 4 with ParamDocView

use of com.google.api.codegen.viewmodel.ParamDocView in project toolkit by googleapis.

the class PhpApiMethodParamTransformer method getMethodParamDocs.

private List<ParamDocView> getMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
    if (context.getMethodModel().getRequestStreaming()) {
        return ImmutableList.of();
    }
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> paramDocs = ImmutableList.builder();
    for (FieldModel field : fields) {
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(context.getNamer().getVariableName(field));
        paramDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(field));
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (methodConfig.isPageStreaming() && methodConfig.getPageStreaming().hasPageSizeField() && field.equals(methodConfig.getPageStreaming().getPageSizeField())) {
            docLines.add("The maximum number of resources contained in the underlying API", "response. The API may return fewer values in a page, even if", "there are additional values to be retrieved.");
        } else if (methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField())) {
            docLines.add("A page token is used to specify a page of values to be returned.", "If no page token is specified (the default), the first page", "of values will be returned. Any page token used here must have", "been generated by a previous call to the API.");
        } else {
            docLines.addAll(context.getNamer().getDocLines(field));
        }
        if (field.isEnum()) {
            // For enums, we alter the param type to int, and document where to find the relevant
            // const values
            String typeNameSingular = context.getTypeTable().getFullNameFor(field.getType().makeOptional());
            if (field.isRepeated()) {
                paramDoc.typeName("int[]");
            } else {
                paramDoc.typeName("int");
            }
            docLines.add("For allowed values, use constants defined on {@see " + typeNameSingular + "}");
        }
        paramDoc.lines(docLines.build());
        paramDocs.add(paramDoc.build());
    }
    return paramDocs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) MapParamDocView(com.google.api.codegen.viewmodel.MapParamDocView) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 5 with ParamDocView

use of com.google.api.codegen.viewmodel.ParamDocView in project toolkit by googleapis.

the class PhpApiMethodParamTransformer method getCallSettingsParamDocList.

private List<ParamDocView> getCallSettingsParamDocList(GapicMethodContext context) {
    ImmutableList.Builder<ParamDocView> arrayKeyDocs = ImmutableList.builder();
    Name retrySettingsName = Name.from("retry", "settings");
    Name timeoutMillisName = Name.from("timeout", "millis");
    if (context.getNamer().methodHasRetrySettings(context.getMethodConfig())) {
        SimpleParamDocView.Builder retrySettingsDoc = SimpleParamDocView.newBuilder();
        retrySettingsDoc.paramName(context.getNamer().localVarName(retrySettingsName));
        String retryDocType = Joiner.on("|").join("RetrySettings", "array");
        retrySettingsDoc.typeName(retryDocType);
        // TODO figure out a reliable way to line-wrap comments across all languages
        // instead of encoding it in the transformer
        StringBuilder retrySettingsDocTextBuilder = new StringBuilder("Retry settings to use for this call. Can be a\n" + "{@see Google\\ApiCore\\RetrySettings} object, or an associative array\n" + "of retry settings parameters. See the documentation on\n" + "{@see Google\\ApiCore\\RetrySettings} for example usage.");
        if (context.getNamer().methodHasTimeoutSettings(context.getMethodConfig())) {
            retrySettingsDocTextBuilder.append(String.format("\nIf specified, then %s is ignored.", context.getNamer().localVarReference(timeoutMillisName)));
        }
        List<String> retrySettingsDocLines = context.getNamer().getDocLines(retrySettingsDocTextBuilder.toString());
        retrySettingsDoc.lines(retrySettingsDocLines);
        arrayKeyDocs.add(retrySettingsDoc.build());
    }
    if (context.getNamer().methodHasTimeoutSettings(context.getMethodConfig())) {
        SimpleParamDocView.Builder timeoutDoc = SimpleParamDocView.newBuilder();
        timeoutDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(TypeRef.of(Type.TYPE_INT32)));
        timeoutDoc.paramName(context.getNamer().localVarName(timeoutMillisName));
        // TODO figure out a reliable way to line-wrap comments across all languages
        // instead of encoding it in the transformer
        StringBuilder timeoutMillisDocTextBuilder = new StringBuilder("Timeout to use for this call.");
        if (context.getNamer().methodHasRetrySettings(context.getMethodConfig())) {
            timeoutMillisDocTextBuilder.append(String.format(" Only used if %s\nis not set.", context.getNamer().localVarReference(retrySettingsName)));
        }
        List<String> timeoutMillisDocLines = context.getNamer().getDocLines(timeoutMillisDocTextBuilder.toString());
        timeoutDoc.lines(timeoutMillisDocLines);
        arrayKeyDocs.add(timeoutDoc.build());
    }
    return arrayKeyDocs.build();
}
Also used : SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) MapParamDocView(com.google.api.codegen.viewmodel.MapParamDocView) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) Name(com.google.api.codegen.util.Name)

Aggregations

ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)9 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)9 FieldModel (com.google.api.codegen.config.FieldModel)6 ImmutableList (com.google.common.collect.ImmutableList)6 MethodConfig (com.google.api.codegen.config.MethodConfig)5 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 MapParamDocView (com.google.api.codegen.viewmodel.MapParamDocView)3 MethodModel (com.google.api.codegen.config.MethodModel)2 Name (com.google.api.codegen.util.Name)2 ArrayList (java.util.ArrayList)2 FieldConfig (com.google.api.codegen.config.FieldConfig)1 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)1 PathTemplateCheckView (com.google.api.codegen.viewmodel.PathTemplateCheckView)1 RequestObjectMethodDetailView (com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)1 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)1