def dict_formatted(value: Any) -> str: """ Return a string with a cross-referencing link for the Dict class and to the refer type. """ dict_with_reference = _get_dict_reference() referenced_value = value.__args__[1] if is_attrs(referenced_value): name = attrs_formatted(referenced_value) elif is_scalar(referenced_value): name = _get_scalar_reference() elif is_array(referenced_value): name = _get_array_reference() else: name = str(referenced_value).replace("typing.", "") return f"{dict_with_reference}[str, {name}]"
def union_formatted(value: Any) -> str: """ Return a string with a cross-referencing link for the Optional module. Note that all usages of union on CaseDescription are from the Optional module. """ optional_with_reference = _get_optional_reference() ref_value = value.__args__[0] if isinstance(ref_value, enum.EnumMeta): name = enum_formatted(ref_value) elif is_array(ref_value): name = _get_array_reference() elif is_list(ref_value): name = f"{_get_list_reference()}[{ref_value.__args__[0].__name__}]" else: name = ref_value.__name__ return f"{optional_with_reference}[{name}]"
def dict_formatted_for_schema(value: Any) -> str: """ Return a string showing a dict with the parameters used, if the parameter is class that has a sphinx reference (attr, Scalar, Array) a cross-referencing link will be added. """ lines = f"\n{BASE_INDENT + INDENT}" lines += "string: " argument = value.__args__[1] if is_attrs(argument): lines += attrs_formatted_for_schema(argument) elif is_union(argument): lines += f"{' | '.join(i.__name__.replace('str', 'string') for i in argument.__args__)}" elif is_scalar(argument): lines += scalar_formatted_for_schema(argument, number_of_indent=2) elif is_array(argument): lines += array_formatted_for_schema(argument, number_of_indent=2) else: lines += argument.__name__ return lines