Accept camelCase JSON keys from OTBR REST API#228
Conversation
The OTBR REST API (per the OpenAPI spec in ot-br-posix) returns camelCase JSON keys (e.g. activeTimestamp, channel, extPanId), but the from_json methods expected PascalCase (ActiveTimestamp, Channel, ExtPanId). Add a key normalization step that maps camelCase to PascalCase before schema validation. PascalCase keys pass through unchanged, so this is fully backward compatible. Fixes home-assistant-libs#227
618b3c1 to
b943b77
Compare
|
@emontnemery Are you fine with this approach? |
agners
left a comment
There was a problem hiding this comment.
In the future, we can look at inverting the case change to be backwards-compatible with older OTBRs instead of the other way around.
Yeah agreed, we could even make an argument to already do that today.
|
|
||
| import voluptuous as vol # type: ignore[import] | ||
|
|
||
| # The OTBR REST API uses camelCase keys (per the OpenAPI spec in ot-br-posix), |
There was a problem hiding this comment.
Hm, I see this is another breaking change of openthread/ot-br-posix#2514, which introduced sweeping changes to the REST API. It follows the JSON API specification, which recommends camelCasing.
Co-authored-by: Stefan Agner <stefan@agner.ch>
|
Thanks for merging the PR! 🚀 |
|
shoulnd't it also emit camelCase as well as accepting it in replies? |

Summary
from_jsonmethods to accept both camelCase and PascalCase JSON keysFixes #227
Changes
models.py: Add_normalize_keys()helper and call it in eachfrom_jsonbefore schema validationtest_models.py: Add tests for camelCase deserializationTest plan
openthread/otbr:latestREST API