def dict_to_auth_scheme(data: Dict[str, Any]) -> AuthScheme:
  """Converts a dictionary to a FastAPI AuthScheme object.

  Args:
      data: The dictionary representing the security scheme.

  Returns:
      A AuthScheme object (APIKey, HTTPBase, OAuth2, OpenIdConnect, or
      HTTPBearer).

  Raises:
      ValueError: If the 'type' field is missing or invalid, or if the
          dictionary cannot be converted to the corresponding Pydantic model.

  Example:
  ```python
  api_key_data = {
      "type": "apiKey",
      "in": "header",
      "name": "X-API-Key",
  }
  api_key_scheme = dict_to_auth_scheme(api_key_data)

  bearer_data = {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "JWT",
  }
  bearer_scheme = dict_to_auth_scheme(bearer_data)


  oauth2_data = {
      "type": "oauth2",
      "flows": {
          "authorizationCode": {
              "authorizationUrl": "https://example.com/auth",
              "tokenUrl": "https://example.com/token",
          }
      }
  }
  oauth2_scheme = dict_to_auth_scheme(oauth2_data)

  openid_data = {
      "type": "openIdConnect",
      "openIdConnectUrl": "https://example.com/.well-known/openid-configuration"
  }
  openid_scheme = dict_to_auth_scheme(openid_data)


  ```
  """
  if "type" not in data:
    raise ValueError("Missing 'type' field in security scheme dictionary.")

  security_type = data["type"]
  try:
    if security_type == "apiKey":
      return APIKey.model_validate(data)
    elif security_type == "http":
      if data.get("scheme") == "bearer":
        return HTTPBearer.model_validate(data)
      else:
        return HTTPBase.model_validate(data)  # Generic HTTP
    elif security_type == "oauth2":
      return OAuth2.model_validate(data)
    elif security_type == "openIdConnect":
      return OpenIdConnect.model_validate(data)
    else:
      raise ValueError(f"Invalid security scheme type: {security_type}")

  except ValidationError as e:
    raise ValueError(f"Invalid security scheme data: {e}") from e
Converts a dictionary to a FastAPI AuthScheme object.

  Args:
      data: The dictionary representing the security scheme.

  Returns:
      A AuthScheme object (APIKey, HTTPBase, OAuth2, OpenIdConnect, or
      HTTPBearer).

  Raises:
      ValueError: If the 'type' field is missing or invalid, or if the
          dictionary cannot be converted to the corresponding Pydantic model.

  Example:
  ```python
  api_key_data = {
      "type": "apiKey",
      "in": "header",
      "name": "X-API-Key",
  }
  api_key_scheme = dict_to_auth_scheme(api_key_data)

  bearer_data = {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "JWT",
  }
  bearer_scheme = dict_to_auth_scheme(bearer_data)


  oauth2_data = {
      "type": "oauth2",
      "flows": {
          "authorizationCode": {
              "authorizationUrl": "https://example.com/auth",
              "tokenUrl": "https://example.com/token",
          }
      }
  }
  oauth2_scheme = dict_to_auth_scheme(oauth2_data)

  openid_data = {
      "type": "openIdConnect",
      "openIdConnectUrl": "https://example.com/.well-known/openid-configuration"
  }
  openid_scheme = dict_to_auth_scheme(openid_data)


  ```
  
src/google/adk/tools/openapi_tool/auth/auth_helpers.py