(api: "lightbus.Api")
return schema
Produce a lightbus schema for the given API
Produce a lightbus schema for the given API
Produce a lightbus schema for the given API
def api_to_schema(api: "lightbus.Api") -> dict:
    """Produce a lightbus schema for the given API"""
    schema = {"rpcs": {}, "events": {}}

    if isinstance(api, type):
        raise InvalidApiForSchemaCreation(
            "An attempt was made to derive an API schema from a type/class, rather than "
            "from an instance of an API. This is probably because you are passing an API "
            "class to api_to_schema(), rather than an instance of the API class."
        )

    for member_name, member in inspect.getmembers(api):
        if member_name.startswith("_"):
            # Don't create schema from private methods
            continue
        if hasattr(Api, member_name):
            # Don't create schema for methods defined on Api class
            continue

        if inspect.ismethod(member):
            schema["rpcs"][member_name] = {
                "parameters": make_rpc_parameter_schema(api.meta.name, member_name, method=member),
                "response": make_response_schema(api.meta.name, member_name, method=member),
            }
        elif isinstance(member, Event):
            schema["events"][member_name] = {
                "parameters": make_event_parameter_schema(api.meta.name, member_name, event=member)
            }

    return schema
def api_to_schema ( api : "lightbus.Api" ) -> dict : schema = { "rpcs" : { } , "events" : { } } if isinstance ( api , type ) : raise InvalidApiForSchemaCreation ( "An attempt was made to derive an API schema from a type/class, rather than " "from an instance of an API. This is probably because you are passing an API " "class to api_to_schema(), rather than an instance of the API class." ) for member_name , member in inspect . getmembers ( api ) : if member_name . startswith ( "_" ) : # Don't create schema from private methods continue if hasattr ( Api , member_name ) : # Don't create schema for methods defined on Api class continue if inspect . ismethod ( member ) : schema [ "rpcs" ] [ member_name ] = { "parameters" : make_rpc_parameter_schema ( api . meta . name , member_name , method = member ) , "response" : make_response_schema ( api . meta . name , member_name , method = member ) , } elif isinstance ( member , Event ) : schema [ "events" ] [ member_name ] = { "parameters" : make_event_parameter_schema ( api . meta . name , member_name , event = member ) } return schema