Skip to content
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

Python - swagger.mustache doesn't appear to deserialize models correctly #281

Closed
dylangleason opened this issue Sep 26, 2014 · 2 comments
Closed

Comments

@dylangleason
Copy link

I have a model with the following specification:

AuthResponse {
    success (int),
    error (Error),
    results (Auth)
}
Error {
    message (string),
    code (int)
}
Auth {
    username (string),
    accessToken (string),
    mode (int),
    clientIp (string)
}

With the following model:

class AuthResponse:

    def __init__(self):
        self.swaggerTypes = {
            'success': 'int',
            'error': 'Error',
            'results': 'Auth'

        }


        self.success = None # int
        self.error = None # Error
        self.results = None # Auth

    def __repr__(self):
        return "<AuthResponse success:%s error:%s results:%s>" % (self.success, self.error, self.results)

However, I noted that swagger.mustache (https://github.com/wordnik/swagger-codegen/blob/master/src/main/resources/python/swagger.mustache) seems to deserialize the object thusly after getting a response from the server:

<AuthResponse success:0 error:<AuthResponse success:None error:None results:None> results:<AuthResponse success:None error:None results:None>>

It doesn't appear that it is correctly deserializing, i.e. the error field contains another AuthResponse object instead of an Error model, and no Auth object in the results field.

Has anyone run into this before? Using the same swagger resource file, I don't appear to have this problem with the PHP client.

@dylangleason dylangleason changed the title swagger.py doesn't appear to deserialize models correctly Python - swagger.mustache doesn't appear to deserialize models correctly Sep 26, 2014
@dylangleason
Copy link
Author

Based on the output it appears that objClass (line 192) never changes, e.g. in the above case it is always AuthResponse. This appears to be fixed by passing attrType to the recursion instead of objClass.

else:
    setattr(instance, attr, self.deserialize(value, 
                                      objClass))  # should be attrType, not objClass

Someone should probably fix this.

@fehguy
Copy link
Contributor

fehguy commented Feb 17, 2015

This should be addressed now. Please reopen if you see an issue still.

@fehguy fehguy closed this as completed Feb 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants