Closed webron closed 7 years ago
Thanks for moving it to the correct project.
@jaccoh It's easy to fix. Would you do the PR ?
sure
but I'm not familiar with the code. Im not sure hardcoding an include is the best way to go if its not needed?
@jaccoh I wonder if you can pull the latest master to give it a try as I've previously fixed some issues related to model import in Python Flask generator. Thanks.
Just tested after cloning the master branch. No dice.
Am I correct in assuming mustache should put that import in there because of this?:
{{#imports}}{{import}}
{{/imports}}
Other imports are simply hardcoded in 'modules/swagger-codegen/target/classes/flaskConnexion/model.mustache'.
Am I correct in assuming mustache should put that import in there because of this?:
Yes, that's correct.
@jaccoh I might have missed it. Can you show the error message you got the starting the Flask server?
It will actually start:
(test) jhoeve-a@laptop-jacco ~/ff/swagger-codegen/out/test master python -m swagger_server
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
But when I call the function from the API:
[2017-03-13 16:19:18,343] ERROR in app: Exception on /api/v3/view/internal/zone/test2.nl./type/A/record/www [PUT]
Traceback (most recent call last):
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/connexion/decorators/validation.py", line 127, in wrapper
response = function(*args, **kwargs)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/connexion/decorators/validation.py", line 290, in wrapper
response = function(*args, **kwargs)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/connexion/decorators/produces.py", line 118, in wrapper
data, status_code, headers = self.get_full_response(function(*args, **kwargs))
File "/home/jhoeve-a/ff/swagger-codegen/out/test/.virtualenv/test/lib/python3.5/site-packages/connexion/decorators/parameter.py", line 156, in wrapper
return function(*args, **kwargs)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/swagger_server/controllers/auth_dns_controller.py", line 246, in record_view_zone_put
paramBody = ParamBody1.from_dict(connexion.request.get_json())
File "/home/jhoeve-a/ff/swagger-codegen/out/test/swagger_server/models/param_body1.py", line 82, in from_dict
return deserialize_model(dikt, cls)
File "/home/jhoeve-a/ff/swagger-codegen/out/test/swagger_server/util.py", line 116, in deserialize_model
setattr(instance, attr, _deserialize(value, attr_type))
File "/home/jhoeve-a/ff/swagger-codegen/out/test/swagger_server/models/param_body1.py", line 244, in contact
if contact is not None and not re.search('', contact):
NameError: name 're' is not defined
Thats because of:
(test) jhoeve-a@laptop-jacco ~/ff/swagger-codegen/out/test master grep 're\.search' * -ri
swagger_server/models/param_body1.py: if ns is not None and not re.search('', ns):
swagger_server/models/param_body1.py: if contact is not None and not re.search('', contact):
You could argue those are re.search are kind of useless in that area.
On a note: The swagger definition is slightly different from the one in the post... but the idea is the same.
@jaccoh the issue should be fixed by #5127. Please pull the latest master to give it a try.
Thanks for the PR by @fabito
The 'import re' is now there. But the regexp aren't:
jhoeve-a@laptop-jacco ~/GitCollections/swagger-codegen/out/test/swagger_server/models master grep 're.search' *
param_body1.py: if ns is not None and not re.search('', ns):
param_body1.py: if contact is not None and not re.search('', contact):
@jaccoh right. I'll take a look.
@jaccoh I've fixed the issue via #5155
Please pull the latest master to give it another try.
done and done
Looks good:
jhoeve-a@laptop-jacco ~/GitCollections/swagger-codegen master cat out/test/swagger_server/models/param_body1.py | grep search
if ns is not None and not re.search('^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\\.$', ns):
if contact is not None and not re.search('^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\\.$', contact):
@jaccoh thanks for verifying the change, and thanks @fabito again for the PR (#5127)
From @jaccoh on February 8, 2017 8:13
Swagger File
Swagger Editor Version 2.10.3
Issue I have in my API definition a few values which I check with 'pattern'. Eg:
Yes I use YAML anchors if the value is reused often.
If I generate a server (python-flask), the models in question are missing an 'import re'. Eg:
That wont work without 're' being imported.
Copied from original issue: swagger-api/swagger-editor#1173