attrs_extractor.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:jsonschema-extractor 作者: toumorokoshi 项目源码 文件源码
def extract(cls, extractor, typ):
        """
        take an attrs based class, and convert it
        to jsonschema.
        """
        schema = {
            "title": typ.__name__,
            "type": "object",
            "properties": {},
            "required": []
        }
        for attribute in attr.fields(typ):
            details = cls._extract_attribute(extractor, attribute)
            if details.is_required:
                schema["required"].append(details.name)
            schema["properties"][details.name] = details.schema
        return schema
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号