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());
}
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());
}
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;
}
Aggregations