From bb3cc503ad59a8f373e137b60b7ed4d12456f0c8 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Thu, 29 Aug 2024 09:15:35 +0545 Subject: [PATCH 1/2] feat: support DetectToxicContent --- src/resty/aws/init.lua | 63 +++++++++++++++++++++++++++++++++ src/resty/aws/request/build.lua | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/resty/aws/init.lua b/src/resty/aws/init.lua index 9d3b9a1..22e10f8 100644 --- a/src/resty/aws/init.lua +++ b/src/resty/aws/init.lua @@ -78,6 +78,66 @@ local aws_config = { api = {}, } +local detect_toxic_content_spec = { + name = "DetectToxicContent", + http = { + method = "POST", + requestUri = "/" + }, + input = { + type = "structure", + members = { + LanguageCode = { + shape = "LanguageCode" + }, + TextSegments = { + member = { + Text = { + shape = "CustomerInputString" + } + }, + type = "list" + } + }, + required = { + "TextSegments", + "LanguageCode" + }, + }, + output = { + type = "structure", + members = { + ResultList = { + member = { + Labels = { + shape = "ListOfLabels" + }, + Toxicity = { + shape = "Float" + } + }, + type = "list" + } + }, + sensitive = true, + }, + errors = { + { + shape = "InvalidRequestException" + }, + { + shape = "TextSizeLimitExceededException" + }, + { + shape = "UnsupportedLanguageException" + }, + { + shape = "InternalServerException" + } + }, +} + + local load_api do -- The API table is a map, where the index is the service-name. The value is a table. @@ -119,6 +179,9 @@ do end api = require(module_name) + if module_name == "resty.aws.raw-api.comprehend-2017-11-27" or module_name == "resty.aws.raw-api.comprehend-latest" then + api.operations["DetectToxicContent"] = detect_toxic_content_spec + end dereference_service(api) cache[module_name] = api diff --git a/src/resty/aws/request/build.lua b/src/resty/aws/request/build.lua index c57e9c9..9ce8851 100644 --- a/src/resty/aws/request/build.lua +++ b/src/resty/aws/request/build.lua @@ -106,7 +106,7 @@ local function build_request(operation, config, params) local body_tbl = {} if config.signingName or config.targetPrefix then - request.headers["X-Amz-Target"] = (config.signingName or config.targetPrefix) .. "." .. operation.name + request.headers["X-Amz-Target"] = (config.targetPrefix or config.signingName) .. "." .. operation.name end if config.protocol == "query" then request.query["Action"] = operation.name From 4eeed8cf12052e7fa5cbf4c1fcebd2a15db975d3 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 30 Aug 2024 09:19:21 +0545 Subject: [PATCH 2/2] only change conditionally --- src/resty/aws/request/build.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/resty/aws/request/build.lua b/src/resty/aws/request/build.lua index 9ce8851..810160b 100644 --- a/src/resty/aws/request/build.lua +++ b/src/resty/aws/request/build.lua @@ -106,7 +106,11 @@ local function build_request(operation, config, params) local body_tbl = {} if config.signingName or config.targetPrefix then - request.headers["X-Amz-Target"] = (config.targetPrefix or config.signingName) .. "." .. operation.name + if operation.name == "DetectToxicContent" then + request.headers["X-Amz-Target"] = (config.targetPrefix or config.signingName) .. "." .. operation.name + else + request.headers["X-Amz-Target"] = (config.signingName or config.targetPrefix) .. "." .. operation.name + end end if config.protocol == "query" then request.query["Action"] = operation.name