Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support DetectToxicContent #7

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/resty/aws/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,66 @@ local aws_config = {
api = {},
}

local detect_toxic_content_spec = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/resty/aws/request/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the x-amz-target should have the Comprehend_20171127 prefix. In this case targetPrefix has the Comprehend_20171127 value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect other APIs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I cannot confirm this. I should change the order only for DetectToxicity then.

end
if config.protocol == "query" then
request.query["Action"] = operation.name
Expand Down
Loading