swagger-api / swagger-api/swagger-codegen

Python-flask generated model class skips validation when parameters passed via constructor

Open
#5,815 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Issue: Bug Server: Python
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I noticed that when constructing an object from an autogenerated class that validations were not done by default.

Swagger-codegen version

java -jar swagger-codegen-cli.jar version
2.2.2

Swagger declaration file content or url
Command line used for generation

java -jar ../swagger-codegen-cli.jar generate -l python-flask -i /ws/mdear-ott/Projects/S3/qmgr/qmgr_api.yaml -c ../generate_options_server.json

pip list
amqp (1.4.6)
amqplib (1.0.2)
AMQPQueue (0.4.2)
anyjson (0.3.3)
APScheduler (3.0.1)
astroid (1.3.2)
backports.ssl-match-hostname (3.4.0.2)
billiard (3.3.0.19)
Candygram (1.0)
celery (3.1.17)
certifi (14.05.14)
CoronaAPI (1.3.0)
crontab (0.20.2)
cx-Oracle (5.1.2)
decorator (3.4.0)
desktop (0.4.2)
distribute (0.7.3)
Django (1.7.1)
ecdsa (0.11)
enum34 (1.0.4)
flower (0.7.3)
FormEncode (1.3.0a1)
frosted (1.4.1)
futures (2.2.0)
fysom (2.0.1)
http-parser (0.8.3)
httplib2 (0.9)
ipaddress (1.0.7)
ipython (2.3.1)
jenkins (1.0.2)
jenkinsapi (0.2.25)
Jinja2 (2.7.3)
kombu (3.0.24)
lockfile (0.10.2)
locknix (1.0.3)
logilab-common (0.63.2)
lxml (3.4.1)
MarkupSafe (0.23)
MySQL-python (1.2.5)
MySQLObject (1.3.1)
ndg-httpsclient (0.4.2)
netaddr (0.7.12)
oauth2 (1.5.211)
oauthlib (0.7.2)
ordereddict (1.1)
paramiko (1.15.1)
pexpect (3.3)
pies (2.6.1)
pies2overrides (2.6.1)
pip (1.5.6)
ply (3.4)
progressbar (2.2)
protobuf (2.6.1)
psutil (2.1.3)
pyasn1 (0.1.9)
pycrypto (2.6.1)
pylint (1.4.0)
pymongo (2.7.2)
PyOpenGL (3.1.0b3)
pyOpenSSL (16.2.0)
pyotp (1.4.1)
pysqlite (2.6.3)
python-daemon (1.6.1)
python-dateutil (2.3)
python-jenkins (0.2)
python-ldap (2.3.13)
pytz (2014.10)
PyYAML (3.11)
requests (2.5.0)
requests-oauth2 (0.2.0)
restkit (4.2.2)
setuptools (7.0)
simplejson (3.6.5)
six (1.8.0)
socketpool (0.5.3)
South (1.0.1)
SQLAlchemy (0.9.8)
sqlite3dbm (0.1.4)
SQLObject (1.7.0)
sqlsoup (0.9.0)
suds-jurko (0.6)
tornado (4.0.2)
Twisted (14.0.2)
tzlocal (1.1.2)
validictory (1.0.0a2)
virtualenv (1.11.6)
web.py (0.37)
wsgiref (0.1.2)
xmlrunner (1.7.7)
zope.interface (4.1.1)

Generated code

CommonReturnModel(Model):
"""
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def init(self, message: str=None, code: str=None):
"""
CommonReturnModel - a model defined in Swagger

    :param message: The message of this CommonReturnModel.
    :type message: str
    :param code: The code of this CommonReturnModel.
    :type code: str
    """
    self.swagger_types = {
        'message': str,
        'code': str
    }

    self.attribute_map = {
        'message': 'message',
        'code': 'code'
    }

    self._message = message
    self._code = code
Steps to reproduce

from qmgr_svr.models.common_failure_return_model import CommonFailureReturnModel

The following should fail validation but does not raise an exception (silently fails):
obj = CommonReturnModel(code="wrong", message="Something bad happened")

In contrast, the following raises an exception:
obj = CommonReturnModel()
obj.code="wrong"
*** ValueError: Invalid value for code (wrong), must be one of ['SUCCESS', 'FAILURE']

Related issues
Suggest a Fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied python-flask generation command and inspect qmgr_svr/models/common_failure_return_model.py, comparing constructor behavior with assignment to code. Trace the generator template responsible for CommonReturnModel.init; done means invalid constructor parameters trigger the same validation failure as later attribute assignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.