(type_, property_names=None)
return schema
Convert a named tuple into a JSON schema

    While a lot of conversations happen in `python_type_to_json_schemas()`, conversion of
    annotated classes is a little more involved. It therefore gets its own function.

    While this is mainly used for named tuples within lightbus, it can also be used for
    general classes.
Convert a named tuple into a JSON schema
Convert a named tuple into a JSON schema
def make_custom_object_schema(type_, property_names=None):
    """Convert a named tuple into a JSON schema

    While a lot of conversations happen in `python_type_to_json_schemas()`, conversion of
    annotated classes is a little more involved. It therefore gets its own function.

    While this is mainly used for named tuples within lightbus, it can also be used for
    general classes.
    """
    if property_names is None:
        # Use typing.get_type_hints() rather than `__annotations__`, as this will resolve
        # forward references
        property_names = [
            p for p in set(list(get_type_hints(type_).keys()) + dir(type_)) if p[0] != "_"
        ]

    properties = {}
    required = []
    for property_name in property_names:
        property_value = getattr(type_, property_name, None)
        if callable(property_value):
            # is a method or dynamic property
            continue

        default = get_property_default(type_, property_name)
        type_hints = get_type_hints(type_)
        if hasattr(type_, "__annotations__") and property_name in type_hints:
            # Use typing.get_type_hints() rather than `__annotations__`, as this will resolve
            # forward references
            properties[property_name] = wrap_with_any_of(
                annotation_to_json_schemas(annotation=type_hints[property_name], default=default)
            )
        elif default is not empty:
            properties[property_name] = wrap_with_any_of(python_type_to_json_schemas(type(default)))
        else:
            properties[property_name] = {}

        if default is empty:
            required.append(property_name)
        else:
            properties[property_name]["default"] = deform_to_bus(default)

    schema = {
        "type": "object",
        "title": type_.__name__,
        "properties": properties,
        "required": required,
        "additionalProperties": False,
    }

    # required key should not be present if it is empty
    if not schema["required"]:
        schema.pop("required")

    return schema
def make_custom_object_schema ( type_ , property_names = None ) : if property_names is None : # Use typing.get_type_hints() rather than `__annotations__`, as this will resolve # forward references property_names = [ p for p in set ( list ( get_type_hints ( type_ ) . keys ( ) ) + dir ( type_ ) ) if p [ 0 ] != "_" ] properties = { } required = [ ] for property_name in property_names : property_value = getattr ( type_ , property_name , None ) if callable ( property_value ) : # is a method or dynamic property continue default = get_property_default ( type_ , property_name ) type_hints = get_type_hints ( type_ ) if hasattr ( type_ , "__annotations__" ) and property_name in type_hints : # Use typing.get_type_hints() rather than `__annotations__`, as this will resolve # forward references properties [ property_name ] = wrap_with_any_of ( annotation_to_json_schemas ( annotation = type_hints [ property_name ] , default = default ) ) elif default is not empty : properties [ property_name ] = wrap_with_any_of ( python_type_to_json_schemas ( type ( default ) ) ) else : properties [ property_name ] = { } if default is empty : required . append ( property_name ) else : properties [ property_name ] [ "default" ] = deform_to_bus ( default ) schema = { "type" : "object" , "title" : type_ . __name__ , "properties" : properties , "required" : required , "additionalProperties" : False , } # required key should not be present if it is empty if not schema [ "required" ] : schema . pop ( "required" ) return schema