(signature: inspect.Signature, annotations: Mapping[str, Any])
| 193 | |
| 194 | |
| 195 | def _build_parameters_schema(signature: inspect.Signature, annotations: Mapping[str, Any]) -> Dict[str, Any]: |
| 196 | properties: Dict[str, Any] = {} |
| 197 | required: List[str] = [] |
| 198 | |
| 199 | for param in signature.parameters.values(): |
| 200 | if param.name.startswith("_"): |
| 201 | continue |
| 202 | if param.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD): |
| 203 | continue |
| 204 | |
| 205 | annotation = annotations.get(param.name, inspect._empty) |
| 206 | annotation, meta = _unwrap_annotation(annotation) |
| 207 | annotation, optional_from_type = _strip_optional(annotation) |
| 208 | schema = _annotation_to_schema(annotation) |
| 209 | schema = _apply_param_meta(schema, meta) |
| 210 | |
| 211 | if param.default is not inspect._empty: |
| 212 | schema.setdefault("default", param.default) |
| 213 | |
| 214 | properties[param.name] = schema |
| 215 | is_required = param.default is inspect._empty and not optional_from_type |
| 216 | if is_required: |
| 217 | required.append(param.name) |
| 218 | |
| 219 | payload: Dict[str, Any] = { |
| 220 | "type": "object", |
| 221 | "properties": properties, |
| 222 | } |
| 223 | if required: |
| 224 | payload["required"] = required |
| 225 | return payload |
| 226 | |
| 227 | |
| 228 | def _unwrap_annotation(annotation: Any) -> Tuple[Any, ParamMeta | None]: |
no test coverage detected