MCPcopy
hub / github.com/pydantic/pydantic / p_arguments_schema

Method p_arguments_schema

pydantic/json_schema.py:1910–1951  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1908 return json_schema
1909
1910 def p_arguments_schema(
1911 self, arguments: list[core_schema.ArgumentsParameter], var_args_schema: CoreSchema | None
1912 ) -> JsonSchemaValue:
1913 """Generates a JSON schema that matches a schema that defines a function's positional arguments.
1914
1915 Args:
1916 arguments: The core schema.
1917
1918 Returns:
1919 The generated JSON schema.
1920 """
1921 prefix_items: list[JsonSchemaValue] = []
1922 min_items = 0
1923
1924 for argument in arguments:
1925 name = self.get_argument_name(argument)
1926
1927 argument_schema = self.generate_inner(argument['schema']).copy()
1928 if 'title' not in argument_schema and self.field_title_should_be_set(argument['schema']):
1929 argument_schema['title'] = self.get_title_from_name(name)
1930 prefix_items.append(argument_schema)
1931
1932 if argument['schema']['type'] != 'default':
1933 # This assumes that if the argument has a default value,
1934 # the inner schema must be of type WithDefaultSchema.
1935 # I believe this is true, but I am not 100% sure
1936 min_items += 1
1937
1938 json_schema: JsonSchemaValue = {'type': 'array'}
1939 if prefix_items:
1940 json_schema['prefixItems'] = prefix_items
1941 if min_items:
1942 json_schema['minItems'] = min_items
1943
1944 if var_args_schema:
1945 items_schema = self.generate_inner(var_args_schema)
1946 if items_schema:
1947 json_schema['items'] = items_schema
1948 else:
1949 json_schema['maxItems'] = len(prefix_items)
1950
1951 return json_schema
1952
1953 def get_argument_name(self, argument: core_schema.ArgumentsParameter | core_schema.ArgumentsV3Parameter) -> str:
1954 """Retrieves the name of an argument.

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