Closed luisgg98 closed 4 months ago
Haven't had a chance to try and run your code but I notice you have a schema_model
defined:
crawler_rss_arg_json_model = api.schema_model('RSSCrawlerRequest', {
"properties":{
config.RSS_URL: {
"type":"string"
},
},
"type": "object"
})
I have had nothing but issues trying to use schema_model
myself. Can you redefine this using the api.model
syntax and see if that solves it?
Hi @peter-doggart ! I've managed to find the reason of the error.
Checking one of the serializers.py files I realized that there was an error defining an object property:
RSS_DOCUMENTID_FIELD: fields.String(fields.String)
This was the reason why Object of type String is not JSON serializable was prompted.
Also I have followed your advise I have changed the way I was defining the schema.
crawler_rss_arg_json_model = api.model(
"RSSCrawlerRequest", {config.RSS_URL: fields.List(fields.String)}
)
Thank you very much!
I'd like to comment with the intention of helping someone avoid (or fix) a simple user error that can lead to a similar problem with the swagger endpoint failing with this message displayed:
In the logs at the end of the stack trace it will say TypeError: Object of type String is not JSON serializable
(or some other object type, such as DateTime - will be whatever the first field type is defined in the schema).
The tricky part is that all tests pass & the API works, it's only the spec that can't be generated. For me this happened when I accidentally omitted an argument from my response declaration:
@api.response(200, my_openapi_schema) # incorrect
@api.response(200, 'Record retrieved', my_openapi_schema) # correct
The problem arises from attempting to serialize the entire schema into the response text string.
swagger.json not found Good afternoon, I'm sorry but this is the first time that I used flask-restx. This API works perfectly I can request the API endpoints and the web services exposed through them works smoothly, however I am not capable of deploying the Swagger endpoint. When I access to the swagger documentation I get the following error "Object of type String is not JSON serializable", I must be placing an String instead of a JSON in somewhere but I can not find where. I have read the documentation -> https://flask-restx.readthedocs.io/en/latest/api.html , even though I not sure where is the failure. I share the code and the error in case someone want to take a look and nice what I'm missing. Thank you very much for reading this issue.
Error on the web browser Screenshot of the error i'm encountering with once I try to access to the Swagger Endpoint
Additional context Add any other context or screenshots about the feature request here.