flask-restx
flask-restx copied to clipboard
Custom Array for Json argument parser
I'm attempting to create a custom array type for argument parsing in the json body. So I created a function and created a schema for it:
type_services.__schema__ = {'type':'array','items':{'type':'string'}}
and create it with
testparser.add_argument(name='services',type=type_services,location='json',required=True)
The type seems to work correctly, when I parse the arguments I get a list of strings. However, it doesn't show it as a field in the json body within the swagger documentation. With that being the only parameter is the json body is being shown as '{}'
When checking the swagger.json, it the items type seems to be missing. I added a "firstName" parameter string for comparison and this is the what I get in the swagger.json
"/customer/test": {
"parameters": [
{
"name": "payload",
"required": true,
"in": "body",
"schema": {
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"services": {
"type": "array"
}
}
}
}
],
"post": {
"responses": {
"200": {
"description": "Success"
}
},
"operationId": "post_create",
"tags": [
"customer"
]
}
}
},
The type: string portion is missing in the schema. Any suggestions?