MCPcopy
hub / github.com/pydantic/pydantic / kw_arguments_schema

Method kw_arguments_schema

pydantic/json_schema.py:1872–1908  ·  view source on GitHub ↗

Generates a JSON schema that matches a schema that defines a function's keyword arguments. Args: arguments: The core schema. Returns: The generated JSON schema.

(
        self, arguments: list[core_schema.ArgumentsParameter], var_kwargs_schema: CoreSchema | None
    )

Source from the content-addressed store, hash-verified

1870 )
1871
1872 def kw_arguments_schema(
1873 self, arguments: list[core_schema.ArgumentsParameter], var_kwargs_schema: CoreSchema | None
1874 ) -> JsonSchemaValue:
1875 """Generates a JSON schema that matches a schema that defines a function's keyword arguments.
1876
1877 Args:
1878 arguments: The core schema.
1879
1880 Returns:
1881 The generated JSON schema.
1882 """
1883 properties: dict[str, JsonSchemaValue] = {}
1884 required: list[str] = []
1885 for argument in arguments:
1886 name = self.get_argument_name(argument)
1887 argument_schema = self.generate_inner(argument['schema']).copy()
1888 if 'title' not in argument_schema and self.field_title_should_be_set(argument['schema']):
1889 argument_schema['title'] = self.get_title_from_name(name)
1890 properties[name] = argument_schema
1891
1892 if argument['schema']['type'] != 'default':
1893 # This assumes that if the argument has a default value,
1894 # the inner schema must be of type WithDefaultSchema.
1895 # I believe this is true, but I am not 100% sure
1896 required.append(name)
1897
1898 json_schema: JsonSchemaValue = {'type': 'object', 'properties': properties}
1899 if required:
1900 json_schema['required'] = required
1901
1902 if var_kwargs_schema:
1903 additional_properties_schema = self.generate_inner(var_kwargs_schema)
1904 if additional_properties_schema:
1905 json_schema['additionalProperties'] = additional_properties_schema
1906 else:
1907 json_schema['additionalProperties'] = False
1908 return json_schema
1909
1910 def p_arguments_schema(
1911 self, arguments: list[core_schema.ArgumentsParameter], var_args_schema: CoreSchema | None

Callers 1

arguments_schemaMethod · 0.95

Calls 5

get_argument_nameMethod · 0.95
generate_innerMethod · 0.95
get_title_from_nameMethod · 0.95
copyMethod · 0.45

Tested by

no test coverage detected