Generates a JSON schema that matches a schema that defines a function's arguments. Args: schema: The core schema. Returns: The generated JSON schema.
(self, schema: core_schema.ArgumentsV3Schema)
| 1969 | return name |
| 1970 | |
| 1971 | def arguments_v3_schema(self, schema: core_schema.ArgumentsV3Schema) -> JsonSchemaValue: |
| 1972 | """Generates a JSON schema that matches a schema that defines a function's arguments. |
| 1973 | |
| 1974 | Args: |
| 1975 | schema: The core schema. |
| 1976 | |
| 1977 | Returns: |
| 1978 | The generated JSON schema. |
| 1979 | """ |
| 1980 | arguments = schema['arguments_schema'] |
| 1981 | properties: dict[str, JsonSchemaValue] = {} |
| 1982 | required: list[str] = [] |
| 1983 | for argument in arguments: |
| 1984 | mode = argument.get('mode', 'positional_or_keyword') |
| 1985 | name = self.get_argument_name(argument) |
| 1986 | argument_schema = self.generate_inner(argument['schema']).copy() |
| 1987 | if mode == 'var_args': |
| 1988 | argument_schema = {'type': 'array', 'items': argument_schema} |
| 1989 | elif mode == 'var_kwargs_uniform': |
| 1990 | argument_schema = {'type': 'object', 'additionalProperties': argument_schema} |
| 1991 | |
| 1992 | argument_schema.setdefault('title', self.get_title_from_name(name)) |
| 1993 | properties[name] = argument_schema |
| 1994 | |
| 1995 | if ( |
| 1996 | (mode == 'var_kwargs_unpacked_typed_dict' and 'required' in argument_schema) |
| 1997 | or mode not in {'var_args', 'var_kwargs_uniform', 'var_kwargs_unpacked_typed_dict'} |
| 1998 | and argument['schema']['type'] != 'default' |
| 1999 | ): |
| 2000 | # This assumes that if the argument has a default value, |
| 2001 | # the inner schema must be of type WithDefaultSchema. |
| 2002 | # I believe this is true, but I am not 100% sure |
| 2003 | required.append(name) |
| 2004 | |
| 2005 | json_schema: JsonSchemaValue = {'type': 'object', 'properties': properties} |
| 2006 | if required: |
| 2007 | json_schema['required'] = required |
| 2008 | return json_schema |
| 2009 | |
| 2010 | def call_schema(self, schema: core_schema.CallSchema) -> JsonSchemaValue: |
| 2011 | """Generates a JSON schema that matches a schema that defines a function call. |