connexion
connexion copied to clipboard
Fix inconsistent behaviour when a charset is defined in Content-Type header value with an invalid and valid json #1202
Fixes
Issue https://github.com/zalando/connexion/issues/1202
I tested it locally here: https://github.com/scoulomb/zalando_connexion_sample (+buildLocalLib branch)
I did not see specific unit test to update, what would you advise?
Coverage increased (+0.6%) to 96.879% when pulling eb9b6a98833b785a885b8b66f6f69003e0aee7b6 on scoulomb:Issue1202 into bed4b95205205861bd6014282d0f61d50231d3ac on zalando:master.
Fix loss of coverage here: https://github.com/zalando/connexion/blob/c99dda68f4cad9e36815267eb68898220499ee5c/connexion/decorators/validation.py#L142
I added unit test in test_json_validation.py However loss of coverage was due to the fact that in the former version of the code we were doing tuple unpacking after the split which could lead to a ValueError exception
>>> mimetype.split('/')
['application-json']
>>> a,b = mimetype.split('/')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 1)
IMO it is a workaround to test a side effect of the function outsside of it: As we now test separator presence it is useless to catch this exception so I will remove the try/except block
Hello @hjacobs , I fixed https://github.com/zalando/connexion/issues/1202 in this PR. Would you mind please have a look? Thanks a lot.
@hjacobs do you think this PR is mergeable, or should I rework on it?
This seems like a good change @scoulomb. If you're still interested in getting it merged, please rebase on and target this PR to the v2
branch.