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
)
| 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 |
no test coverage detected