Search in sources :

Example 1 with PathTemplateCheckView

use of com.google.api.codegen.viewmodel.PathTemplateCheckView 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 2 with PathTemplateCheckView

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

the class StaticLangApiMethodTransformer method setCallableMethodFields.

private void setCallableMethodFields(MethodContext context, String callableName, Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(context.getNamer().getDocLines(method, context.getMethodConfig())).paramDocs(new ArrayList<ParamDocView>()).throwsDocLines(new ArrayList<String>()).build());
    methodViewBuilder.initCode(initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject)));
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    String genericAwareResponseTypeFullName = context.getNamer().getGenericAwareResponseTypeName(context);
    String genericAwareResponseType = context.getTypeTable().getAndSaveNicknameFor(genericAwareResponseTypeFullName);
    MethodConfig methodConfig = context.getMethodConfig();
    ApiCallableImplType callableImplType = ApiCallableImplType.SimpleApiCallable;
    if (methodConfig.isGrpcStreaming()) {
        callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType());
    } else if (methodConfig.isBatching()) {
        callableImplType = ApiCallableImplType.BatchingApiCallable;
    }
    methodViewBuilder.callableMethod(CallableMethodDetailView.newBuilder().genericAwareResponseType(genericAwareResponseType).callableName(callableName).interfaceTypeName(context.getNamer().getApiCallableTypeName(callableImplType.serviceMethodType())).build());
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 3 with PathTemplateCheckView

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

the class StaticLangApiMethodTransformer method generatePathTemplateChecks.

private List<PathTemplateCheckView> generatePathTemplateChecks(MethodContext context, Iterable<FieldConfig> fieldConfigs) {
    List<PathTemplateCheckView> pathTemplateChecks = new ArrayList<>();
    if (!context.getFeatureConfig().enableStringFormatFunctions()) {
        return pathTemplateChecks;
    }
    for (FieldConfig fieldConfig : fieldConfigs) {
        if (!fieldConfig.useValidation()) {
            // Don't generate a path template check if fieldConfig is not configured to use validation.
            continue;
        }
        FieldModel field = fieldConfig.getField();
        ImmutableMap<String, String> fieldNamePatterns = context.getMethodConfig().getFieldNamePatterns();
        String entityName = fieldNamePatterns.get(field.getSimpleName());
        if (entityName != null) {
            SingleResourceNameConfig resourceNameConfig = context.getSingleResourceNameConfig(entityName);
            if (resourceNameConfig == null) {
                String methodName = context.getMethodModel().getSimpleName();
                throw new IllegalStateException("No collection config with id '" + entityName + "' required by configuration for method '" + methodName + "'");
            }
            PathTemplateCheckView.Builder check = PathTemplateCheckView.newBuilder();
            check.pathTemplateName(context.getNamer().getPathTemplateName(context.getInterfaceConfig(), resourceNameConfig));
            check.paramName(context.getNamer().getVariableName(field));
            check.allowEmptyString(shouldAllowEmpty(context, field));
            check.validationMessageContext(context.getNamer().getApiMethodName(context.getMethodModel(), context.getMethodConfig().getVisibility()));
            pathTemplateChecks.add(check.build());
        }
    }
    return pathTemplateChecks;
}
Also used : PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Aggregations

PathTemplateCheckView (com.google.api.codegen.viewmodel.PathTemplateCheckView)3 ArrayList (java.util.ArrayList)3 MethodModel (com.google.api.codegen.config.MethodModel)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2 FieldConfig (com.google.api.codegen.config.FieldConfig)1 FieldModel (com.google.api.codegen.config.FieldModel)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 ApiCallableImplType (com.google.api.codegen.viewmodel.ApiCallableImplType)1 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)1 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)1 RequestObjectMethodDetailView (com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)1 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)1