fix(reqpreprocessor): support camelCase context attributes for beckn spec migration

- Add transactionId and messageId as camelCase aliases in model.go contextKeys map,
  pointing to the same ContextKeyTxnID and ContextKeyMsgID constants. This allows
  adapter configs to reference either form without failing startup validation.

- In reqpreprocessor, add firstNonNil() helper for subscriber/caller ID lookups
  so bap_id/bapId and bpp_id/bppId are both resolved correctly regardless of
  which beckn spec version the payload uses. snake_case takes precedence when both
  are present.

- Add snakeToCamel() helper used in the context key loop so a single config entry
  (e.g. transaction_id) automatically also checks the camelCase form (transactionId)
  without requiring any config file changes.

- Add TestSnakeToCamel, TestCamelCaseSubscriberID, TestCamelCaseContextKeys to
  cover all new code paths.

Fixes #637

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mayuresh
2026-03-25 15:40:36 +05:30
parent 6d4f45a632
commit 1be757a165
5 changed files with 275 additions and 7 deletions

View File

@@ -62,12 +62,16 @@ const (
)
var contextKeys = map[string]ContextKey{
// snake_case keys (legacy beckn spec)
"transaction_id": ContextKeyTxnID,
"message_id": ContextKeyMsgID,
"subscriber_id": ContextKeySubscriberID,
"module_id": ContextKeyModuleID,
"parent_id": ContextKeyParentID,
"remote_id": ContextKeyRemoteID,
// camelCase aliases (new beckn spec — map to the same internal constants)
"transactionId": ContextKeyTxnID,
"messageId": ContextKeyMsgID,
}
// ParseContextKey converts a string into a valid ContextKey.