Description
I want to show the minimum value of a query parameter in the docs, so I am using Schema constructor with @openapi.parameter decorator. It works great when using in app route directly. However, it starts giving error when I use the same method in blueprints. I am attaching sample code and screenshots below.
What's working
here is the sample code that works correct
This code initializes perfect but when I navigate to /docs it gives the following error in console:
[12240] [ERROR] Exception occurred while handling uri: 'http://localhost:8000/docs/openapi.json'
Traceback (most recent call last):
File "E:\workplace\sanic-openapi-problem\venv\Lib\site-packages\sanic\app.py", line 974, in handle_request
response = await response
^^^^^^^^^^^^^^
File "E:\workplace\sanic-openapi-problem\venv\Lib\site-packages\sanic_ext\extensions\openapi\blueprint.py", line 109, in spec
return json(SpecificationBuilder().build(request.app).serialize())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\workplace\sanic-openapi-problem\venv\Lib\site-packages\sanic\response\convenience.py", line 50, in json
return JSONResponse(
^^^^^^^^^^^^^
File "E:\workplace\sanic-openapi-problem\venv\Lib\site-packages\sanic\response\types.py", line 361, in __init__
self._encode_body(self._use_dumps(body, **self._use_dumps_kwargs)),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Ansari\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 238, in dumps
**kw).encode(obj)
^^^^^^^^^^^
File "C:\Users\Ansari\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Ansari\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 258, in iterencode
return _iterencode(o, 0)
^^^^^^^^^^^^^^^^^
File "C:\Users\Ansari\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type type is not JSON serializable
And on the web it gives this error.
Environment:
OS: Windows 10
Browser: chrome
Sanic: v23.3.0
sanic-routing: 22.8.0
sanic-ext: 23.3.0
python: 3.11.3
Additional context
It works fine when I use docstrings as documentation, but I can't use docstrings because some of my query params are complex and will require a lot of writing everytime something changes. So, I want to make it work with @openapi.parameter decorator.
Description I want to show the minimum value of a query parameter in the docs, so I am using Schema constructor with @openapi.parameter decorator. It works great when using in app route directly. However, it starts giving error when I use the same method in blueprints. I am attaching sample code and screenshots below.
What's working here is the sample code that works correct
Notice the Schema constructor being used. It gives the docs also as expected.
What does not work (Steps to reproduce) Here is the sample code that doesn't work. It involves two files.
This code initializes perfect but when I navigate to /docs it gives the following error in console:
And on the web it gives this error.
Environment:
Additional context It works fine when I use docstrings as documentation, but I can't use docstrings because some of my query params are complex and will require a lot of writing everytime something changes. So, I want to make it work with @openapi.parameter decorator.