-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describing nested dictionaries followed by dynamic keys for marshal_with #737
Comments
Hello, What you are looking for is Wildcard fields. Details may be found here: #728 (comment) |
So, in the end, your model will look like: MODEL_DOC = api.model('Document', {
CREATOR: fields.String(description='Creator e-mail.'),
SUBJECT: fields.String(description='Subject.'),
FILENAME: fields.String(description='Filename.'),
DATE: fields.DateTime(description='Generation date.'),
AUTHOR: fields.String(description='Author name.'),
R1: fields.String(description='1st recipient name.'),
R2: fields.String(description='2nd recipient name.'),
R3: fields.String(description='3rd recipient name.'),
SENT: fields.Boolean(description='Sent status.')
})
MODEL_NEST = fields.Nested(MODEL_DOC)
MODEL_WILD = fields.Wildcard(MODEL_NEST)
MODEL_DOCS = api.model('Documents', {
'*': MODEL_WILD
})
MODEL_DOWNLOAD_RESPONSE = api.model('Document Download Response', {
'number': fields.Integer(description='Document number.'),
'docs': fields.Nested(MODEL_DOCS, description='Dictionary with documents number as key and document data as value.')
}) Note: it's important to define your |
Now closing as the patch has been merged |
Hi all! When will this be released in a new version? It has been merged in November last year, but it's not available in PyPI. |
speaking as a maintainer -- flask-restplus has been declared dead. The only person with keys to release has left the project, and didn't hand anything over. There is an official fork at https://github.com/python-restx/flask-restx https://pypi.org/project/flask-restx/ it's a drop in replacement, just change your import names This commit is in the first release of flask-restx (as it was slated for the 0.14 release that never occurred) |
Thank you very much @j5awry ! |
Hello. I may not understand examples I have found regarding describing model of dictionary with different names as keys cause I have no idea how to describe bellow model properly:
In "docs" I'm planning to change into simple list of objects but for the moment I would like to describe model in which "docs" is a dictionary of smaller dictionaries indicated by keys {"number_1": MODEL_DOC, "number_2": MODEL_DOC}. I was trying to achieve it as bellow but I have now idea how to describe "(document_number)" to indicate that there could be many different document dictionaries followed by document numbers as key (strings).
Best regards
Kietna Qu'Tak
The text was updated successfully, but these errors were encountered: