caikit.runtime.http_server.utils

This module holds utility functions and classes used only by the REST server, this includes things like parameter handles and openapi spec generation

Functions

convert_json_schema_to_multipart(json_schema, defs)

Helper function to convert a json schema from applicaiton/json into one

_extract_raw_from_schema(json_schema, defs, Any][, ...])

Helper function to extract all "bytes" or File fields from a json schema and return the

_clean_schema_path(path)

Clean a schema path of all reserved openapi fields. For example this turns

_parse_raw_json_schema(→ Optional[dict])

Helper to check if a json schema matches a raw objects schema. If it does return the generic

flatten_json_schema(→ dict)

Function to flatten a json schema. It replaces all references to $def

_replace_json_refs(current_json, refs_map)

Helper function to replace all items of {'$ref':'#/<refs>'} with the raw

update_dict_at_dot_path(→ bool)

Helper to set values in a dict using 'foo.bar' key notation

Module Contents

caikit.runtime.http_server.utils.convert_json_schema_to_multipart(json_schema, defs)[source]

Helper function to convert a json schema from applicaiton/json into one that can be used for multipart requests

caikit.runtime.http_server.utils._extract_raw_from_schema(json_schema: Any, defs: Dict[str, Any], current_path=None)[source]

Helper function to extract all “bytes” or File fields from a json schema and return the cleaned schema dict and a dict of extracted schemas where the key is the original raw’s path

caikit.runtime.http_server.utils._clean_schema_path(path)[source]

Clean a schema path of all reserved openapi fields. For example this turns inputs.properties.anyOf.file.properties.filename to inputs.file.filename

caikit.runtime.http_server.utils._parse_raw_json_schema(json_schema: dict) dict | None[source]

Helper to check if a json schema matches a raw objects schema. If it does return the generic binary openapi schema

caikit.runtime.http_server.utils.flatten_json_schema(json_schema: dict) dict[source]

Function to flatten a json schema. It replaces all references to $def with the requested object or {} if it’s not found

caikit.runtime.http_server.utils._replace_json_refs(current_json: Any, refs_map: dict)[source]

Helper function to replace all items of {‘$ref’:’#/<refs>’} with the raw objects. This is used for generating flattened openapi specs

caikit.runtime.http_server.utils.update_dict_at_dot_path(dict_obj: dict, key: str, updated_value: Any) bool[source]

Helper to set values in a dict using ‘foo.bar’ key notation

Args:
dict_obj: dict

The dict into which the key will be set

key: str

Key that may contain ‘.’ notation indicating dict nesting

updated_value: Any

The value to place at the nested key

Returns:
bool:

Weather the dict was successfully updated