将中间模型声明转换为openapi、jsonschema或任何其他需要的模式

middle-schema的Python项目详细描述


将您的middle模型声明转换为openapi、jsonschema或您需要的任何其他模式!

一言以蔽之

>>> importenum>>> importjson>>> importtypingast>>> importmiddle>>> frommiddle_schema.openapiimportparse>>> @enum.unique... classPlatformEnum(str,enum.Enum):... XBOX1="XBOX1"... PLAYSTATION4="PLAYSTATION4"... PC="PC">>> @enum.unique... classLanguageEnum(enum.IntEnum):... ENGLISH=1... JAPANESE=2... SPANISH=3... GERMAN=4... PORTUGUESE=5>>> @enum.unique... classCityRegionEnum(str,enum.Enum):... TROPICAL="TROPICAL"... TEMPERATE="TEMPERATE"... BOREAL="BOREAL">>> classCity(middle.Model):... __description__="One awesome city built"... name=middle.field(type=str,description="The city name")... region=middle.field(... default=CityRegionEnum.TEMPERATE,... type=CityRegionEnum,... description="The region this city is located",... )>>> classPlayer(middle.Model):... nickname=middle.field(... type=str,description="The nickname of the player over the internet"... )... youtube_channel=middle.field(... type=str,description="The YouTube channel of the player",default=None... )>>> classGame(middle.Model):... __description__="An electronic game model"... name=middle.field(type=str,description="The name of the game")... platform=middle.field(... type=PlatformEnum,description="Which platform it runs on"... )... score=middle.field(... type=float,... description="The average score of the game",... minimum=0,... maximum=10,... multiple_of=0.1,... )... resolution_tested=middle.field(... type=str,... description="The resolution which the game was tested",... pattern="^\d+x\d+$",... )... genre=middle.field(... type=t.List[str],... description="One or more genres this game is part of",... min_items=1,... unique_items=True,... )... rating=middle.field(... type=t.Dict[str,float],... description="Ratings given on specialized websites",... min_properties=3,... )... players=middle.field(... type=t.Set[str],... description="Some of the notorious players of this game",... )... language=middle.field(... type=LanguageEnum,description="The main language of the game"... )... awesome_city=middle.field(type=City)... remarkable_resources=middle.field(... type=t.Union[Player,City],... description="Some remarkable resources of this game over the internet",... )>>> api=parse(Game)>>> json.dumps(api.specification,indent=4,sort_keys=True){
    "description": "An electronic game model",
    "properties": {
        "awesome_city": {
            "description": "One awesome city built",
            "properties": {
                "name": {
                    "description": "The city name",
                    "type": "string"
                },
                "region": {
                    "choices": [
                        "TROPICAL",
                        "TEMPERATE",
                        "BOREAL"
                    ],
                    "description": "The region this city is located",
                    "type": "string"
                }
            },
            "required": [
                "name"
            ],
            "type": "object"
        },
        "genre": {
            "description": "One or more genres this game is part of",
            "items": {
                "type": "string"
            },
            "minItems": 1,
            "type": "array",
            "uniqueItems": true
        },
        "language": {
            "choices": [
                1,
                2,
                3,
                4,
                5
            ],
            "description": "The main language of the game",
            "format": "int64",
            "type": "integer"
        },
        "name": {
            "description": "The name of the game",
            "type": "string"
        },
        "platform": {
            "choices": [
                "XBOX1",
                "PLAYSTATION4",
                "PC"
            ],
            "description": "Which platform it runs on",
            "type": "string"
        },
        "players": {
            "description": "Some of the notorious players of this game",
            "items": {
                "properties": {
                    "nickname": {
                        "description": "The nickname of the player over the internet",
                        "type": "string"
                    },
                    "youtube_channel": {
                        "description": "The YouTube channel of the player",
                        "type": "string"
                    }
                },
                "required": [
                    "nickname"
                ],
                "type": "object"
            },
            "type": "array"
        },
        "rating": {
            "additionalProperties": {
                "format": "double",
                "type": "number"
            },
            "description": "Ratings given on specialized websites",
            "minProperties": 3,
            "type": "object"
        },
        "remarkable_resources": {
            "anyOf": [
                {
                    "properties": {
                        "nickname": {
                            "description": "The nickname of the player over the internet",
                            "type": "string"
                        },
                        "youtube_channel": {
                            "description": "The YouTube channel of the player",
                            "type": "string"
                        }
                    },
                    "required": [
                        "nickname"
                    ],
                    "type": "object"
                },
                {
                    "description": "One awesome city built",
                    "properties": {
                        "name": {
                            "description": "The city name",
                            "type": "string"
                        },
                        "region": {
                            "choices": [
                                "TROPICAL",
                                "TEMPERATE",
                                "BOREAL"
                            ],
                            "description": "The region this city is located",
                            "type": "string"
                        }
                    },
                    "required": [
                        "name"
                    ],
                    "type": "object"
                }
            ],
            "description": "Some remarkable resources of this game over the internet"
        },
        "resolution_tested": {
            "description": "The resolution which the game was tested",
            "pattern": "^\\d+x\\d+$",
            "type": "string"
        },
        "score": {
            "description": "The average score of the game",
            "format": "double",
            "maximum": 10,
            "minimum": 0,
            "multipleOf": 0.1,
            "type": "number"
        }
    },
    "required": [
        "name",
        "platform",
        "score",
        "resolution_tested",
        "genre",
        "rating",
        "players",
        "language",
        "awesome_city",
        "remarkable_resources"
    ],
    "type": "object"
}

警告

重要的middlemiddle-schema处于非常早期的开发阶段!请谨慎使用,并注意某些功能和api可能会在不同版本之间发生变化,直到它们超出alpha

许可证

middle-schema是根据MIT许可证发行的自由软件

变更日志

2018年8月1日v0.2.0

  • 骨架分析器上的小型重构;
  • middlemodels;的openapi组件和模式生成
  • 99%以上的代码覆盖率。

2018年7月26日v0.1.0

  • pypi上的第一个版本。不稳定

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带truezip的java拆分zip   java Spring,AppEngine:在AppEngine的数据源中添加postgresql url   java Android coverflow   java以编程方式创建复合过滤器,以在log4j 2中定义多个过滤器   java jpa eclipselink异常[eclipselink 4002]   中的java WordNet数据库目录相对路径。罐子   java无法在Spring Boot 2/3中显示登录的用户   java Onetomany:未找到联接表错误   java数据模型演化   java方法在类型列表中添加的(对象)不适用于参数(int)意味着什么?   用java打印两个数组   java SNMP4J发送从不超时   java添加/删除联系人(EditText)+类别(SpinnerBox),可以根据需要动态添加/删除多个联系人   语句和PreparedStatement之间的java差异   java在运行作为JAR归档文件分发的项目时加载图像等资源   来自应用程序或外部服务器的java Cron作业   多线程Java并发:并发添加和清除列表项   java更改单元测试的私有方法行为