是否可以将值设置为零以下和最大值,JsonSchema?

问题描述 投票:0回答:1

我想验证温度和冷却因子的值是否小于零,但是我不确定是否使用最小值:例如,-10,-20是否正确使用。

对于温度,冷却系数和风速的实际最大值也是如此。

什么是正确使用?

非常感谢。

JsonSchema的用法如下:

 "type": "object",
    "properties": {
        "weather": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "windSpeed": {
                        "type": "number",
                        "minimum": 0.00
                    },
                    "cityName": {
                        "type": "string"
                    },
                    "currentConditions": {
                        "type": "string",
                        "enum": [ "Cloud", "Snow", "Sun", "Hail", "Rain", "Sleet", "Heavy Rain"]
                    },
                    "temperature": {
                        "type": "number",
                        "minimum": 0.00
                    },
                    "windDirection": {
                        "type": "string",
                        "enum": ["Northerly", "North easterly", "Easterly", "South easterly", "Southerly", "South westerly", "Westerly", "North westerly"]
                    },
                    "windChillFactor": {
                        "type": "number",
                        "minimum": 0.00
                    }

                },
                "required": ["cityId", "cityName", "currentConditions", "temperature", "windSpeed", "windDirection", "windChillFactor"]

            }
        }
    }
}
json jsonschema weather weather-api json-schema-validator
1个回答
0
投票

通常,当不确定这类事情时,我建议采用以下两种方法之一:

  1. 咨询json-schema.org/understanding-json-schema。此处,仅将multipleOf描述为仅允许使用正值,但对于minimum / maximum,任何数值(包括负数)都应该是正确的(即使为简单起见,示例仅使用正值)。
  2. 使用jsonschemavalidator.net之类的在线验证器根据示例数据测试您的模式,以查看其是否按照您期望的那样通过验证。

  3. 此外,您的架构看起来还不错。您可能想将cityId包括在weather.items.properties中(而不仅仅是在weather.items.required中)以指示其类型。

© www.soinside.com 2019 - 2024. All rights reserved.