def _get_dump(self, api_name=None): if api_name: schema = {api_name: self.get_api_schema(api_name)} else: schema = {api_name: self.get_api_schema(api_name) for api_name in self.api_names} indent = 2 if self.human_readable else None return json_encode(schema, indent=indent)
def handle(self, args): schema = json_encode(config_as_json_schema(), indent=2, sort_keys=True) if args.out: with open(args.out, "w", encoding="utf8") as f: f.write(schema) else: print(schema)
def test_config_as_json_schema_dump(): """Make sure we can encode the schema as json We may have some custom types kicking around (i.e. frozendict()) """ schema = config_as_json_schema() encoded = json_encode(schema) assert encoded json.loads(encoded)
async def store(self, api_name: str, schema: Dict, ttl_seconds: Optional[int]): """Store an individual schema""" with await self.connection_manager() as redis: schema_key = self.schema_key(api_name) p = redis.pipeline() p.set(schema_key, json_encode(schema)) if ttl_seconds is not None: p.expire(schema_key, ttl_seconds) p.sadd(self.schema_set_key(), api_name) await p.execute()
def handle(self, args, config, plugin_registry: PluginRegistry): self.setup_logging(args.log_level or "warning", config) bus_module, bus = self.import_bus(args) schema = json_encode(config_as_json_schema(), indent=2, sort_keys=True) if args.schema: with open(args.schema, "w", encoding="utf8") as f: f.write(schema) else: print(schema)