Skip to content

Emit camelCase keys in as_json() to match OTBR REST API spec#239

Open
jnilo1 wants to merge 1 commit intohome-assistant-libs:mainfrom
jnilo1:fix/as-json-camelcase
Open

Emit camelCase keys in as_json() to match OTBR REST API spec#239
jnilo1 wants to merge 1 commit intohome-assistant-libs:mainfrom
jnilo1:fix/as-json-camelcase

Conversation

@jnilo1
Copy link
Copy Markdown

@jnilo1 jnilo1 commented Apr 4, 2026

Summary

  • Add _to_camel_keys() (inverse of _normalize_keys()) and apply it in as_json() for Timestamp, SecurityPolicy, ActiveDataSet and PendingDataSet
  • PUT/POST requests now emit camelCase keys matching the OTBR REST OpenAPI spec
  • GET parsing unchanged — both camelCase and PascalCase still accepted via _normalize_keys()

Context

Commit 5e5197a (shipped in v2.9.0) fixed from_json() to accept camelCase GET responses, but as_json() still emitted PascalCase in PUT requests. Upstream ot-br-posix uses cJSON_GetObjectItemCaseSensitive to parse incoming payloads, so PascalCase keys are silently rejected — causing "Failed to call OTBR API" errors in Home Assistant when changing Thread channel or dataset.

Fixes #238

Test plan

  • All existing tests updated and passing (51/51)
  • New tests for as_json() camelCase serialization
  • Roundtrip test: from_json(as_json(x)) == x

Commit 5e5197a added _normalize_keys() to accept camelCase in GET
responses, but as_json() still emitted PascalCase in PUT requests.
The upstream ot-br-posix REST API uses cJSON_GetObjectItemCaseSensitive
to parse incoming payloads, so PascalCase keys are silently rejected.

Add _to_camel_keys() (inverse of _normalize_keys) and apply it in
as_json() for Timestamp, SecurityPolicy, ActiveDataSet and
PendingDataSet. GET parsing is unchanged (both cases still accepted).

Fixes home-assistant-libs#238
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.

as_json() still emits PascalCase keys in PUT requests (counterpart of #227)

1 participant