Skip to content

The Plaid client configuration failed to support case-insensitive dictionary keys, snake_case fallbacks, and keyword-arguments-based initialization. This prevented developers from using common Python patterns (such as passing snake_case keys or direct kwargs) without manual dictionary normalization. #587

Description

@sin-strokes

The Plaid client configuration failed to support case-insensitive dictionary keys, snake_case fallbacks, and keyword-arguments-based initialization. This prevented developers from using common Python patterns (such as passing snake_case keys or direct kwargs) without manual dictionary normalization.

Case-Insensitive Dictionary Normalization

  • Implemented a custom CaseInsensitiveDict subclassing dict that normalizes string keys to lowercase and strips separators (_ and -), mapping keys like client_id, CLIENT_ID, and client-id transparently to clientId.
  • Overrode dictionary methods (__getitem__, __setitem__, __delitem__, __contains__, get, pop, setdefault, update, copy) to maintain standard dictionary semantics under normalization.
  • Simplified get_api_key_with_prefix and auth_settings to leverage CaseInsensitiveDict directly, removing redundant iteration and manual casing fallback blocks.

Constructor Convenience & Property Setters

  • Added support for direct keyword arguments (client_id, secret, plaid_version, environment) to the Configuration constructor, mapping them automatically into api_key and setting host from environment.
  • Wrapped api_key and api_key_prefix with property setters to automatically cast standard dictionaries into CaseInsensitiveDict wrappers.

Code Generator Template Parity

  • Replicated identical logic within the template file templates/python/configuration.mustache to ensure custom behaviors remain resilient across any future OpenAPI generator rebuilds.

Example Usage

import plaid

# Initialization using direct keyword arguments and environment aliases
configuration = plaid.Configuration(
    client_id="your-client-id",
    secret="your-secret",
    plaid_version="2020-09-14",
    environment="sandbox"
)

# Case and separator-insensitive key access
assert configuration.api_key['clientId'] == "your-client-id"
assert configuration.api_key['client_id'] == "your-client-id"

# In-place mutations are automatically normalized
configuration.api_key['CLIENT_ID'] = "new-client-id"
assert configuration.get_api_key_with_prefix('clientId') == "new-client-id"

Originally posted by @Copilot in sin-strokes#1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions