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

Improve the code to support int and other types and cast them to string #498

Merged
merged 2 commits into from
Jan 17, 2020

Conversation

thesunwave
Copy link
Contributor

@thesunwave thesunwave commented Jan 9, 2020

Hey, how about this solution @jhendrixMSFT? This code accepts interface but casts types not always right. I mean isn't this more correct to cast not only string arrays to string if that function accepts not only strings? If we accept it then we don't need to fix a swagger spec.

realates with Azure/azure-sdk-for-go#6586

As part of submitting, please make sure you can make the following assertions:

  • I've tested my changes, adding unit tests if applicable.
  • I've added Apache 2.0 Headers to the top of any new source files.
  • I'm submitting this PR to the dev branch, except in the case of urgent bug fixes warranting their own release.
  • If I'm targeting master, I've updated CHANGELOG.md to address the changes I'm making.

@msftclas
Copy link

msftclas commented Jan 9, 2020

CLA assistant check
All CLA requirements met.

@thesunwave
Copy link
Contributor Author

is anybody here?

@jhendrixMSFT
Copy link
Member

jhendrixMSFT commented Jan 15, 2020

Sorry for the delay.

While the change looks fine, the code comment states the following.

// AsStringSlice method converts interface{} to []string. This expects a
//that the parameter passed to be a slice or array of a type that has the underlying
//type a string.

It could be the case that the comment is incorrect, but we need to be sure this isn't going to break anything before it can be merged. I will investigate further later in the week.

@thesunwave
Copy link
Contributor Author

Thank you @jhendrixMSFT.

@jhendrixMSFT
Copy link
Member

I dug into this a bit more. Per issue #207, AsStringSlice() was introduced to support cognitive services. While the issue doesn't mention the specifics, I believe this was to fix cases where collections of enums are used as parameters. The original code simply would type-assert interface{} to []string which would panic for slices of enums.

Since the underlying type of enums is string, this function was introduced to handle that case. Unfortunately collections of integers were never considered, either they didn't exist at the time or their failure was obscured by the enum case; and since this change "fixed" integers we never noticed it was spewing out bad values.

I've updated the code comment and CHANGELOG with info on the fix.

@jhendrixMSFT jhendrixMSFT merged commit c3a71f0 into Azure:master Jan 17, 2020
alrs pushed a commit to alrs/go-autorest that referenced this pull request Mar 6, 2020
…ng (Azure#498)

* Improve the code to support int and other types and cast them to string

* Updated comment, version info and changelog

Co-authored-by: Joel Hendrix <jhendrix@microsoft.com>
@thesunwave thesunwave deleted the fix/improve_as_string_slice branch December 22, 2020 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants