-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Question] [Swift6] All Codable classes into querystring #20997
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
Comments
Tagging @4brunu |
Honestly I would like to simplify things, because there are old things in the swift generator that doesn't make sense or are not needed anymore, but I'm a bit afraid of breaking things, so we should be careful with that changes. This was introduced here Another thing that we should do is rename useJsonEncodable to useQueryString. Also, inspired by this issue, I already started so clean up of old things and some fixes. |
I agree that this doesn't look correct. This change was introduced to fix this issue. If we remove this code
Then I think the models will use the default implementation
which is also not correct. But sending a model for example a user in a query parameter also feels wrong. Honestly I'm a bit lost in this. @x-sheep What do you think of this? @0x0c could you help with this? Thanks |
I don't think QueryStringEncodable (or in fact the old JSONEncodable) should ever be used for models... Right now the generator will break up a model class into a function with multiple parameters, if the function expects a Query string or a Multipart body. So it will generate a class for a model, but not use it. (unless there's a different call that expects that model in a regular JSON body). The whole idea of serializing a model to JSON, then converting it to Base64, is not something I can find in any OpenAPI specification. Nor do I expect an API to actually want such a request. So I would be in favor of removing QueryStringEncodable for models, and only keeping it for enums, primitive values and the Foundation Data struct (which can keep the base64 behavior). If this does break behavior for users (which my gut tells me is unlikely) it's still possible to use JSONEncoder yourself and then pass in the Data value to the generated function. |
@x-sheep looks good to me. Could you please create a PR? |
Hi, I found another bug related to QueryStringEncodable introduction in this PR #20906. Lines 477 to 535 in 6e3b199
we check for the type of parameter and encode it according to the type. But with This created s bug that instead of uploading a file, it was uploading the path of the file. Instead of returning a And since the |
@4brunu You're right. I think it's a better idea to make an enum called
QueryStringEncodable (or whatever it'll be called) can then return one of these, and we can avoid casting to specific values. |
That would require a lot of changes in the generator. |
Sounds good to me. |
Uh oh!
There was an error while loading. Please reload this page.
In the current Swift6 generator (and Swift5) with version
7.13.0-snapshot
a non-standard class that conforms to Encodable is serialized by first converting it to JSON, and then base64-encoding the result.Is this being used at all? It would seem much nicer to me if this was done explicitly by a user, and leave only the serialization of Data (byte arrays) to Base64 as a standard. Right now, this behavior is implicit whenever an object is passed into a request that uses it as a query parameter.
The text was updated successfully, but these errors were encountered: