Skip to content

Commit 92f1dbe

Browse files
committed
fix: correct API parameter formats for createRedactions
- Move includeAnnotations/includeText to strategyOptions (not root level) - Use camelCase for API parameters (caseSensitive, wholeWordsOnly) - Put appearance options in 'content' object with correct names (fillColor, outlineColor) - Simplify createRedactions handler to pass through strategyOptions directly - Remove unsupported stroke_width parameter These changes align with the Nutrient API OpenAPI specification.
1 parent b667868 commit 92f1dbe

File tree

2 files changed

+38
-49
lines changed

2 files changed

+38
-49
lines changed

src/nutrient_dws/api/direct.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,23 @@ def create_redactions_preset(
321321
"""
322322
options = {
323323
"strategy": "preset",
324-
"strategy_options": {"preset": preset},
325-
"include_annotations": include_annotations,
326-
"include_text": include_text,
324+
"strategy_options": {
325+
"preset": preset,
326+
"includeAnnotations": include_annotations,
327+
"includeText": include_text,
328+
},
327329
}
328330

329331
# Add appearance options if provided
332+
content = {}
330333
if appearance_fill_color:
331-
options["appearance_fill_color"] = appearance_fill_color
334+
content["fillColor"] = appearance_fill_color
332335
if appearance_stroke_color:
333-
options["appearance_stroke_color"] = appearance_stroke_color
334-
if appearance_stroke_width is not None:
335-
options["appearance_stroke_width"] = appearance_stroke_width
336+
content["outlineColor"] = appearance_stroke_color
337+
# Note: stroke width is not supported by the API
338+
339+
if content:
340+
options["content"] = content
336341

337342
return self._process_file("create-redactions", input_file, output_path, **options)
338343

@@ -378,19 +383,22 @@ def create_redactions_regex(
378383
"strategy": "regex",
379384
"strategy_options": {
380385
"pattern": pattern,
381-
"case_sensitive": case_sensitive,
386+
"caseSensitive": case_sensitive,
387+
"includeAnnotations": include_annotations,
388+
"includeText": include_text,
382389
},
383-
"include_annotations": include_annotations,
384-
"include_text": include_text,
385390
}
386391

387392
# Add appearance options if provided
393+
content = {}
388394
if appearance_fill_color:
389-
options["appearance_fill_color"] = appearance_fill_color
395+
content["fillColor"] = appearance_fill_color
390396
if appearance_stroke_color:
391-
options["appearance_stroke_color"] = appearance_stroke_color
392-
if appearance_stroke_width is not None:
393-
options["appearance_stroke_width"] = appearance_stroke_width
397+
content["outlineColor"] = appearance_stroke_color
398+
# Note: stroke width is not supported by the API
399+
400+
if content:
401+
options["content"] = content
394402

395403
return self._process_file("create-redactions", input_file, output_path, **options)
396404

@@ -438,20 +446,23 @@ def create_redactions_text(
438446
"strategy": "text",
439447
"strategy_options": {
440448
"text": text,
441-
"case_sensitive": case_sensitive,
442-
"whole_words_only": whole_words_only,
449+
"caseSensitive": case_sensitive,
450+
"wholeWordsOnly": whole_words_only,
451+
"includeAnnotations": include_annotations,
452+
"includeText": include_text,
443453
},
444-
"include_annotations": include_annotations,
445-
"include_text": include_text,
446454
}
447455

448456
# Add appearance options if provided
457+
content = {}
449458
if appearance_fill_color:
450-
options["appearance_fill_color"] = appearance_fill_color
459+
content["fillColor"] = appearance_fill_color
451460
if appearance_stroke_color:
452-
options["appearance_stroke_color"] = appearance_stroke_color
453-
if appearance_stroke_width is not None:
454-
options["appearance_stroke_width"] = appearance_stroke_width
461+
content["outlineColor"] = appearance_stroke_color
462+
# Note: stroke width is not supported by the API
463+
464+
if content:
465+
options["content"] = content
455466

456467
return self._process_file("create-redactions", input_file, output_path, **options)
457468

src/nutrient_dws/builder.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -230,36 +230,14 @@ def _map_tool_to_action(self, tool: str, options: dict[str, Any]) -> dict[str, A
230230
action["position"] = options["position"]
231231

232232
case "createRedactions":
233-
# Handle create redactions with strategy options
233+
# Handle create redactions - pass through directly
234+
# The direct.py already formats everything correctly
234235
if "strategy" in options:
235236
action["strategy"] = options["strategy"]
236237
if "strategy_options" in options:
237-
# Map strategy_options based on strategy type
238-
strategy = options.get("strategy", "")
239-
if strategy == "preset":
240-
action["preset"] = options["strategy_options"].get("preset")
241-
elif strategy == "regex":
242-
action["pattern"] = options["strategy_options"].get("pattern")
243-
if "case_sensitive" in options["strategy_options"]:
244-
action["caseSensitive"] = options["strategy_options"]["case_sensitive"]
245-
elif strategy == "text":
246-
action["text"] = options["strategy_options"].get("text")
247-
if "case_sensitive" in options["strategy_options"]:
248-
action["caseSensitive"] = options["strategy_options"]["case_sensitive"]
249-
if "whole_words_only" in options["strategy_options"]:
250-
action["wholeWordsOnly"] = options["strategy_options"][
251-
"whole_words_only"
252-
]
253-
254-
# Copy over other options
255-
for key, value in options.items():
256-
if key not in ["strategy", "strategy_options"]:
257-
# Convert snake_case to camelCase for API
258-
camel_key = "".join(
259-
word.capitalize() if i else word
260-
for i, word in enumerate(key.split("_"))
261-
)
262-
action[camel_key] = value
238+
action["strategyOptions"] = options["strategy_options"]
239+
if "content" in options:
240+
action["content"] = options["content"]
263241

264242
case "optimize":
265243
# Handle optimize action with camelCase conversion

0 commit comments

Comments
 (0)