def get_event_schema(self, api_name, event_name): event_schemas = self.get_api_schema(api_name)["events"] try: return event_schemas[event_name] except KeyError: raise SchemaNotFound( "Found schema for API '{}', but it did not contain an event named '{}'" "".format(api_name, event_name))
def get_rpc_schema(self, api_name, rpc_name): rpc_schemas = self.get_api_schema(api_name)["rpcs"] try: return rpc_schemas[rpc_name] except KeyError: raise SchemaNotFound( "Found schema for API '{}', but it did not contain a RPC named '{}'" "".format(api_name, rpc_name))
def get_api_schema(self, api_name) -> Optional[dict]: """Get the schema for the given API""" api_schema = self.local_schemas.get( api_name) or self.remote_schemas.get(api_name) if not api_schema: # TODO: Add link to docs in error message raise SchemaNotFound( "No schema could be found for API {}. You should ensure that either this " "API is being served by another lightbus process, or you can load this schema manually." "".format(api_name)) return api_schema
def get_event_or_rpc_schema(self, api_name, name): try: return self.get_event_schema(api_name, name) except SchemaNotFound: pass try: return self.get_rpc_schema(api_name, name) except SchemaNotFound: pass # TODO: Add link to docs in error message raise SchemaNotFound( "No schema found for '{}' on API '{}'. You should either, a) ensure this " "API is being served by another lightbus process, or b) load this schema manually." "".format(api_name, name))