Open timothytierney opened 6 years ago
I found a way to do this using the fields.Raw option.
Define your array:
networks_array = [
{
'ipaddress': "",
'macaddress': "",
'Enable': True,
'networktype': ""
},
{
'ipaddress': "",
'macaddress': "",
'Enable': True,
'networktype': ""
}
]
in my model, I defined a fields.Raw as
'networks': fields.Raw(example=networks_array, type=json)
and it displays
"networks": [ { "macaddress": "", "networktype": "", "Enable": true, "ipaddress": "" }, { "macaddress": "", "networktype": "", "Enable": true, "ipaddress": "" } ]
Try to use enum like this:
resource_test_fields = api.model('test model', {
'networks': fields.String(description="your description", enum=your_custom_list)}
)
I have a networks_fields model that I'm trying to display in a sample swagger payload that displays 2 dicts in list that is nested (bottom has my ending result I'm looking for).
I can only get payload in swagger to display the nested list as a single entry: { "networks": [ { "dhcpEnable": true, "macaddress": "string", "networktype": "string", "ipaddress": "string" } ] }
How do I get the swagger payload to display two elements in this list, like below? { "networks": [ { "dhcpEnable": true, "macaddress": "string", "networktype": "string", "ipaddress": "string" }, { "dhcpEnable": true, "macaddress": "string", "networktype": "string", "ipaddress": "string" } ] }
networks_fields = api.model('networks', { 'ipaddress': fields.String, 'macaddress': fields.String, 'dhcpEnable': fields.Boolean(default=True), 'networktype': fields.String})
resource_test_fields = api.model('test', { 'networks': fields.List(fields.Nested(networks_fields))})
@vc.route('/test/api/v1.0/hosts/,')
class add_test(Resource):
Thanks for looking.