Comments (1)
We have a similar problem with schemas created from direct imports from flask_marshmallow
. The serializer doesn't know what to do with the schema's Meta
class:
ERROR:root:jsonify failure; defaulting to json.dumps
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/flasgger/base.py", line 164, in get
return jsonify(self.loader())
File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 342, in jsonify
return current_app.json.response(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/flask/json/provider.py", line 309, in response
f"{self.dumps(obj, **dump_args)}\n", mimetype=mimetype
File "/opt/swept/api/swept_api/__init__.py", line 55, in dumps
return _json.dumps(obj, cls=ExtendedJSONEncoder, **kwargs)
File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
return cls(
File "/usr/local/lib/python3.9/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/local/lib/python3.9/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/local/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.9/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/opt/swept/api/swept_api/__init__.py", line 50, in default
return super().default(o)
File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type SchemaMeta is not JSON serializable
Pipfile:
apispec = "*"
flask = "==2.2.0"
flask-marshmallow = "==0.15.0"
flask-sqlalchemy = "==3.0.2"
marshmallow = "==3.9.0"
marshmallow-sqlalchemy = "==0.24.0"
sqlalchemy = "==2.0.0"
As mentioned in #590, downgrading to flasgger = "==0.9.5"
resolves the SchemaMeta
issue, but instead raises a different error for us:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1758, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1734, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/usr/local/lib/python3.9/site-packages/flask/views.py", line 107, in view
return current_app.ensure_sync(self.dispatch_request)(**kwargs)
File "/usr/local/lib/python3.9/site-packages/flask/views.py", line 188, in dispatch_request
return current_app.ensure_sync(meth)(**kwargs)
File "/usr/local/lib/python3.9/site-packages/flasgger/base.py", line 133, in get
return jsonify(self.loader())
File "/usr/local/lib/python3.9/site-packages/flasgger/base.py", line 399, in get_apispecs
specs = get_specs(
File "/usr/local/lib/python3.9/site-packages/flasgger/utils.py", line 134, in get_specs
convert_schemas(apispec_swag, apispec_definitions)
File "/usr/local/lib/python3.9/site-packages/flasgger/marshmallow_apispec.py", line 109, in convert_schemas
v = convert_schemas(v, definitions)
File "/usr/local/lib/python3.9/site-packages/flasgger/marshmallow_apispec.py", line 123, in convert_schemas
definitions[v.__name__] = schema2jsonschema(v)
File "/usr/local/lib/python3.9/site-packages/apispec/ext/marshmallow/openapi.py", line 256, in schema2jsonschema
jsonschema = self.fields2jsonschema(fields, partial=partial)
File "/usr/local/lib/python3.9/site-packages/apispec/ext/marshmallow/openapi.py", line 281, in fields2jsonschema
prop = self.field2property(field_obj)
File "/usr/local/lib/python3.9/site-packages/apispec/ext/marshmallow/field_converter.py", line 174, in field2property
ret.update(attr_func(field, ret=ret))
File "/usr/local/lib/python3.9/site-packages/apispec/ext/marshmallow/field_converter.py", line 224, in field2default
default = field.load_default
AttributeError: 'String' object has no attribute 'load_default'
The only schema currently attached to a view is extremely simple:
from flasgger import Schema, fields
class InviteUserSchema(Schema):
class Meta:
strict = True
message = fields.Str(required=True)
subject = fields.Str(required=True)
In the view extended from SwaggerView
, we pass the schema to definitions
. If this line is commented out, the docs load without the schema definition, otherwise they raise the error above:
definitions = {"InviteUserSchema": InviteUserSchema}
from flasgger.
Related Issues (20)
- sdist is missing tox.ini
- Switch from `pep8` to `pycodestyle`
- Unable to use import in yaml definitions with relative path
- Unhandled error around self.SCHEMA_TYPES
- Schema with no required fields crashes HOT 1
- disable swagger route until authorization HOT 3
- How can I protect the swagger endpoints, by making it a child of another existing endpoint? HOT 1
- Flassger support for parameter type:file HOT 3
- Query parameter not getting picked up in `parsed_data` after 0.9.5
- apispec is missing in the run-time requirements in setup.py
- 1 test fails: ModuleNotFoundError: No module named 'flasgger_package'
- Data validation with swag_from doesn't work with OpenAPI 3
- Not serving .js and .css files? HOT 1
- Duplicate API Versioning Prefix in Swagger UI Paths with Base URL Configuration
- swag_from default location
- Swagger interface allows the injection of JavaScript code
- Flasgger does not work because the uiversion is loaded as a string
- OpenAPI client generator docs link?
- swag_from with "schema": MyMarshmallowSchema always generates Swagger 2.0 style references
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flasgger.