swagger UI breaks if using openAPI 3.0.0
- Dominant language
- Python
- Stars
- 652
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
I've got a project which works perfectly at openapi version "2.0".
Changing to openAPI "3.0.0" causes an error-
```
TypeError: Object of type 'MyCoolMashmallowSchema' is not JSON serializable
```
this is my app configuration-
```
app.config.update(
{
"APISPEC_SPEC": APISpec(
title="Neptune Payload Manager",
version=app_version,
openapi_version='3.0.0',
plugins=[MarshmallowPlugin()],
),
"APISPEC_SWAGGER_UI_URL": "/",
"APISPEC_SWAGGER_URL": "/json",
}
)
```
this is my schema-
```
class MyCoolMashmallowSchema(Schema):
class Meta:
strict = True
name = fields.Str()
description = fields.Str()
class MyCoolObject:
# Not strictly necessary, but convenient to be able to access the schema this way
schema = MyCoolMarshmallowSchema
def __init__(
self,
name: str,
description: str,
):
self.name = name
self.description = description
@post_load
def make_model(self, data):
return MyCoolObject(
data["name"],
data["description"],
)
```
and my resource
```
@doc(
tags=['My Cool Object']
)
@marshal_with(MyCoolObject.schema(many=True), code=200, description='OK')
class MyCoolObjectListResource(MethodResource):
store: List[MyCoolObject] = [
MyCoolObject('test1', 'this is a made up object'),
MyCoolObject('test2', 'this is also a made up object'),
MyCoolObject('test3', 'this is also also a made up object'),
]
def get(self):
return self.store
```
anything obvious jump out?
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure using the APISpec configuration with openapi_version='3.0.0', then inspect the /json endpoint and Swagger UI response for the non-serializable schema. Compare the result with openapi_version='2.0'; done means the OpenAPI 3.0 specification is JSON-serializable and the UI loads successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100