Dorthu / openapi3

A Python3 OpenAPI 3 Spec Parser
BSD 3-Clause "New" or "Revised" License
116 stars 47 forks source link

openapi3.errors.SpecError: Expected components.schemas.Foobar.properties.foobar.default to be one of [<class 'float'>], got <class 'int'> #122

Open luckydonald opened 1 month ago

luckydonald commented 1 month ago

Based on https://demo.grocy.info/api/openapi/specification:

{
  "openapi": "3.1.0",
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "min_stock_amount": {
            "type": "number",
            "minimum": 0,
            "default": 0
          }
        },
        "example": {
          "min_stock_amount": "8"
        }
      }
    }
  }
}

Produces

openapi3.errors.SpecError: Expected components.schemas.Product.properties.min_stock_amount.default 
to be one of [<class 'float'>], got <class 'int'>
luckydonald commented 1 month ago

In my local testing around,

TYPE_LOOKUP = {
    "array": list,
    "integer": int,
    "object": dict,
    "string": str,
    "boolean": bool,
-   "number": float,
+   "number": [float, int],
}

made it work.

Pretty sure the kind of error is related to #29 and #30.

luckydonald commented 1 month ago

I did a bit of work for this on #123, but unfortunately I can't compile uvloop, hence I can't run any tests on it (or create any)