swagger-py-codegen
swagger-py-codegen copied to clipboard
TypeError exception in response validation with falcon framework
Running code generated for falcon framework from the following yaml file
https://forge.etsi.org/gitlab/mec/gs011-app-enablement-api/blob/master/Mp1.yaml
I get an exception for every response that the application tries to send out:
[2019-02-14 09:36:04 +0000] [17948] [ERROR] Error handling request /exampleAPI/mp1/v1/applications/applicazione1/dns_rules
Traceback (most recent call last):
File "/src/var/mec/prova_venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/src/var/mec/prova_venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/src/var/mec/prova_venv/lib/python2.7/site-packages/falcon/api.py", line 244, in __call__
responder(req, resp, **params)
File "/src/var/mec/prova_venv/lib/python2.7/site-packages/falcon/hooks.py", line 182, in do_after
shim(req, resp, self, *action_args, **action_kwargs)
File "/src/var/mec/swagger_test/mp1_ref/mp1_ref/exampleAPI_mp1_v1/validators.py", line 169, in response_filter
description='`%d` is not a defined status code.' % status)
TypeError: %d format: a number is required, not NoneType
This is due to the fact that in validators.py
(function response_filter
) the status
variable is (in falcon) a string containing the status code and the reason phrase, while filter
is a dictionary indexed by status code as integer.
My workaround is the following:
- status = None
-
- if len(filter) == 1:
- if six.PY3:
- status = list(filter.keys())[0]
- else:
- status = filter.keys()[0]
+ status = int(resp.status.split()[0])