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

[JAVASCRIPT] Only generate api without the models #3996

Open
triptec opened this issue Oct 14, 2016 · 4 comments
Open

[JAVASCRIPT] Only generate api without the models #3996

triptec opened this issue Oct 14, 2016 · 4 comments

Comments

@triptec
Copy link
Contributor

triptec commented Oct 14, 2016

I'm using a generated swagger client in a reactjs project where we use Immutable, I would like to get the data as a json map instead of models. Is it only me that have a need for something like this?

An alternative would be to implement a toJSON() that would return the object representation.

@wing328
Copy link
Contributor

wing328 commented Oct 14, 2016

The toJSON method was removed. Please refer to the discussion in #2288

@triptec
Copy link
Contributor Author

triptec commented Oct 14, 2016

Yes, I saw this. That would mean me doing:

resModel = client.getModels();
resObject = JSON.parse(JSON.stringify(resModel));

I would mush prefer

resModel = client.getModels();
resObject = resModel.toJSON();

JSON.stringify also calls toJSON() and not toJson() so it would allow for internal properties on the model that would not be serialized if we don't want them to.

@wing328
Copy link
Contributor

wing328 commented Oct 14, 2016

And here is what I said before: #2075 (comment)

@triptec
Copy link
Contributor Author

triptec commented Oct 14, 2016

@wing328 sorry but I'm not suggesting an implementation like:

ResModel.prototype.toJson = function() {
    return JSON.stringify(this);
}

but something along the lines of:

ResModel.prototype.toJSON = function() {
    return {
        "someString": this["someString"],
        "someArray": this["someArray"],
        "someOtherModel": this["someOtherModel"].toJSON()
    }
}

@wing328 wing328 modified the milestones: Future, v2.2.2 Feb 16, 2017
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