python-jsonschema / jsonschema

An implementation of the JSON Schema specification for Python
https://python-jsonschema.readthedocs.io
MIT License
4.6k stars 580 forks source link

wiered issue #1166

Closed wanghaisheng closed 1 year ago

wanghaisheng commented 1 year ago

schema like this

                        templateschema = {
                                        "$schema": "http://json-schema.org/draft-04/schema#",
                                        "type": "object",
                                        "properties": {
                                            "canvasWidth": {
                                            "type": "integer"
                                            },
                                            "canvasHeight": {
                                            "type": "integer"
                                            },
                                            "texts": {
                                            "type": "array",
                                            "items": [
                                                {
                                                "type": "object",
                                                "properties": {
                                                    "textType": {
                                                    "type": "string"
                                                    },
                                                    "fontFile": {
                                                    "type": "string"
                                                    },
                                                    "x": {
                                                    "type": "integer"
                                                    },
                                                    "y": {
                                                    "type": "integer"
                                                    },
                                                    "width": {
                                                    "type": "integer"
                                                    },
                                                    "height": {
                                                    "type": "integer"
                                                    },
                                                    "topLeft": {
                                                    "type": "string"
                                                    },
                                                    "topRight": {
                                                    "type": "string"
                                                    },
                                                    "bottomLeft": {
                                                    "type": "string"
                                                    },
                                                    "bottomRight": {
                                                    "type": "string"
                                                    },
                                                    "fontSize": {
                                                    "type": "integer"
                                                    },
                                                    "fontName": {
                                                    "type": "string"
                                                    },
                                                    "gridSize": {
                                                    "type": "integer"
                                                    },
                                                    "nearestGridSerialNumber": {
                                                    "type": "integer"
                                                    },
                                                    "fontcolor": {
                                                    "type": "string"
                                                    }
                                                },
                                                "required": [
                                                    "textType",
                                                    "fontFile",
                                                    "x",
                                                    "y",
                                                    "width",
                                                    "height",
                                                    "topLeft",
                                                    "topRight",
                                                    "bottomLeft",
                                                    "bottomRight",
                                                    "fontSize",
                                                    "fontName",
                                                    "gridSize",
                                                    "nearestGridSerialNumber",
                                                    "fontcolor"
                                                ]
                                                }
                                            ]
                                            }
                                        },
                                        "required": [
                                            "canvasWidth",
                                            "canvasHeight",
                                            "texts"
                                        ]
                                        }

instance is

{'canvasWidth': 1480, 'canvasHeight': 1080, 'texts': [{'textType': 'heading', 'fontFile': '', 'x': 349, 'y': 452, 'width': 788, 'height': 88, 'topLeft': '(349, 452)', 'topRight': '(1137, 452)', 'bottomLeft': '(349, 540)', 
'bottomRight': '(1137, 540)', 'fontSize': 22, 'fontName': 'Unknown', 'gridSize': 10, 'nearestGridSerialNumber': 43, 'fontcolor': 'rgb(0, 240, 255)'}]}
                    except Exception as e:
                        logger.error(f'this thumb template json dont follow json schema format,check the error msg:\n{e}')
                        print(e)

throw me a 'width'