MCPcopy Create free account
hub / github.com/OpenRouterTeam/python-sdk / _populate_query_params

Function _populate_query_params

src/openrouter/utils/queryparams.py:41–111  ·  view source on GitHub ↗
(
    query_params: Any,
    gbls: Any,
    query_param_values: Dict[str, List[str]],
    skip_fields: List[str],
    allow_empty_value: Optional[List[str]] = None,
)

Source from the content-addressed store, hash-verified

39
40
41def _populate_query_params(
42 query_params: Any,
43 gbls: Any,
44 query_param_values: Dict[str, List[str]],
45 skip_fields: List[str],
46 allow_empty_value: Optional[List[str]] = None,
47) -> List[str]:
48 globals_already_populated: List[str] = []
49
50 if not isinstance(query_params, BaseModel):
51 return globals_already_populated
52
53 param_fields: Dict[str, FieldInfo] = query_params.__class__.model_fields
54 param_field_types = get_type_hints(query_params.__class__)
55 for name in param_fields:
56 if name in skip_fields:
57 continue
58
59 field = param_fields[name]
60
61 metadata = find_field_metadata(field, QueryParamMetadata)
62 if not metadata:
63 continue
64
65 value = getattr(query_params, name) if _is_set(query_params) else None
66
67 value, global_found = _populate_from_globals(
68 name, value, QueryParamMetadata, gbls
69 )
70 if global_found:
71 globals_already_populated.append(name)
72
73 f_name = field.alias if field.alias is not None else name
74
75 allow_empty_set = set(allow_empty_value or [])
76 should_include_empty = f_name in allow_empty_set and (
77 value is None or value == [] or value == ""
78 )
79
80 if should_include_empty:
81 query_param_values[f_name] = [""]
82 continue
83
84 serialization = metadata.serialization
85 if serialization is not None:
86 serialized_parms = _get_serialized_params(
87 metadata, f_name, value, param_field_types[name]
88 )
89 for key, value in serialized_parms.items():
90 if key in query_param_values:
91 query_param_values[key].extend(value)
92 else:
93 query_param_values[key] = [value]
94 else:
95 style = metadata.style
96 if style == "deepObject":
97 _populate_deep_object_query_params(f_name, value, query_param_values)
98 elif style == "form":

Callers 1

get_query_paramsFunction · 0.85

Calls 6

find_field_metadataFunction · 0.85
_is_setFunction · 0.85
_populate_from_globalsFunction · 0.85
_get_serialized_paramsFunction · 0.85

Tested by

no test coverage detected