Skip to content

[Swift] two fixes to latest param mapping code #4587

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

Merged
merged 5 commits into from
Jan 25, 2017
Merged

[Swift] two fixes to latest param mapping code #4587

merged 5 commits into from
Jan 25, 2017

Conversation

jaz-ah
Copy link
Contributor

@jaz-ah jaz-ah commented Jan 17, 2017

PR checklist

  • [ x] Read the contribution guildelines.
  • [x ] Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • [x ] Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

  1. extra ?'s at end of some url's
    -if you had nil parameters passed into a function, then you would get an api call like:
    http://foo.com?

  2. enums not being called out w/ rawValue to get the proper string name
    -if you defined an enum:
    enum {
    foo = "Foo"
    }
    the new mapping wouldn't call rawValue so you would get the lowercase foo instead of Foo

@jaz-ah jaz-ah changed the title two fixes: 1) extra ?'s at end of some url's 2) enums not being calle… [Swift] two fixes to latest param mapping code Jan 17, 2017
@jaz-ah
Copy link
Contributor Author

jaz-ah commented Jan 17, 2017

cc'ing @tomekc who made the original change in #4490 if you could look @ this one
cc'ing @jgavris @Edubits @hexelon

@@ -130,7 +130,7 @@ open class {{classname}}: APIBase {
{{#hasQueryParams}}
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
{{#queryParams}}
"{{paramName}}": {{paramName}}{{#hasMore}}, {{/hasMore}}
"{{paramName}}": {{paramName}}{{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{^required}}?{{/required}}.rawValue{{/isContainer}}{{/isEnum}}{{#hasMore}}, {{/hasMore}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is now correct, but I'd address the readability of this fragment in the future.
What isContainer means by the way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y - I actually have to make one more fix here - this isn't all the way correct yet. let me see if I cleanup the readability as well.

"enumQueryInteger": enumQueryInteger
"enum_query_string_array": enumQueryStringArray,
"enum_query_string": enumQueryString?.rawValue,
"enum_query_integer": enumQueryInteger?.encodeToJSON()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomekc @wing328 is this correct for the integer value - was this broken as well? I notice the double above in the formParams wasn't encoded...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me locally - looks like the correct change.

@jgavris
Copy link
Contributor

jgavris commented Jan 18, 2017

I can check this out tomorrow as a smoke test in our project. Would love to improve the test coverage since #4490 was passing. @wing328 could you give us an example of using the fake petstore?

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Jan 19, 2017

@jgavris did the new code work out for you?

@jgavris
Copy link
Contributor

jgavris commented Jan 19, 2017

@jaz-ah We're actually running the 2.3.0 branch and there are conflicts with master at the moment. I might have to defer to someone else.

@wing328
Copy link
Contributor

wing328 commented Jan 19, 2017

could you give us an example of using the fake petstore?

C#, PHP, Python, Ruby and more are using fake petstore for testing.

https://github.com/swagger-api/swagger-codegen/blob/master/bin/csharp-petstore.sh
https://github.com/swagger-api/swagger-codegen/blob/master/bin/python-petstore.sh
https://github.com/swagger-api/swagger-codegen/blob/master/bin/php-petstore.sh
https://github.com/swagger-api/swagger-codegen/blob/master/bin/ruby-petstore.sh

Is that what you're looking for?

Totally agree with you about adding an additional test cases, if not too difficult, to cover this issue.

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Jan 20, 2017

@wing328 might be a little more difficult - I'd need to run testEnumParametersWithRequestBuilder and I need a different cased enum, and the the server to fail if the case of the enum isn't correct... unless you have an idea of a different way to test this one - I agree we should have something to make sure this doesn't break in the future. (also not sure why the build broke on this)

@wing328
Copy link
Contributor

wing328 commented Jan 22, 2017

@jaz-ah right, definitely not easy. I'll create a task to track various test cases we want to include.

Petstore (fake or original) definitely is not the best spec for testing various test cases. Moving forward, we want to leverage one of the server stub generators to generate server code covering more scenarios.

@wing328 wing328 modified the milestones: Future, v2.2.2 Jan 22, 2017
@jaz-ah
Copy link
Contributor Author

jaz-ah commented Jan 22, 2017

@wing328 not sure why this build isn't building though... (this succeeds for me)

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2017

@jaz-ah I've restarted the jobs and the results now look good.

PR merged into master.

@wing328 wing328 merged commit f592fdb into swagger-api:master Jan 25, 2017
davidgri pushed a commit to davidgri/swagger-codegen that referenced this pull request May 11, 2017
* two fixes: 1) extra ?'s at end of some url's 2) enums not being called out w/ rawValue to get the proper string name

* update samples

* one step closer

* closer implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants