Skip to content

feat(bfabric_scripts): JSON input for the api commands - #617

Draft
leoschwarz wants to merge 2 commits into
refactor/api-cli-trimfrom
feat/api-json-input
Draft

feat(bfabric_scripts): JSON input for the api commands#617
leoschwarz wants to merge 2 commits into
refactor/api-cli-trimfrom
feat/api-json-input

Conversation

@leoschwarz

Copy link
Copy Markdown
Member
  • Add --json and --json-file to api read, api create and api update — the only way to pass a nested or non-string attribute value.
  • Merge the JSON object over the key-value pairs, rejecting a key given in both.
  • Fix api create rejecting an id attribute; the check never fired before.

Stacked on #616 — review that one first, and expect this diff to shrink once it merges.

Closes #159

🤖 Prepared with assistance from Claude Opus 5 via Claude Code.

Closes #159.

api read, create and update accept --json and --json-file, which is the only
way to pass a nested or non-string attribute value. Both live on Query, so all
three commands get them without per-command code; cyclopts treats a field-level
Parameter(name="--json") as an absolute name, so they surface as plain --json
rather than --query.json.

The JSON object is merged over the key-value pairs and a key given in both is
rejected, rather than silently letting one win.

Two fixes fell out of this:

- validate_query's dict branch returned {"pairs": ...}, dropping every other
  key, so the new fields vanished whenever positional pairs were also given.
- create's _must_not_contain_id iterated the model rather than the attributes,
  so it yielded field names and never once caught an id attribute. Both the
  pairs and the JSON path are checked now.
@leoschwarz
leoschwarz changed the base branch from main to refactor/api-cli-trim August 24, 2026 14:14
# Conflicts:
#	bfabric_scripts/docs/changelog.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON input for bfabric-cli api commands

1 participant