Skip to content

[csharp] Return ICollection<T> instead of List<T> #1964

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 4 commits into from
Jan 25, 2016

Conversation

jimschubert
Copy link
Contributor

This change is inline with Microsoft's recommended guidelines for
collections
.

This code is based on the discussion in #1338

As mentioned in the issue, converting method signatures to return ICollection<T> rather than List<T> should be considered a breaking change.

This change also reduces the specific type of input parameters from List<T> to ICollection<T>, which is not a breaking change because List<T> implements ICollection<T>.

@wing328
Copy link
Contributor

wing328 commented Jan 24, 2016

@jimschubert thanks for the PR. Given that it's a breaking (non-backward compatible) change, I would suggest adding a CLI option (e.g. returnICollection) that defaults to false to begin with.

This change is inline with Microsoft's recommended guidelines for
collects
(https://msdn.microsoft.com/en-us/library/dn169389(v=vs.110).aspx).

Added generator options for csharp to:

* useCollection: Deserialize responses into and return Collection<T>
* returnICollection: For List<T> or Collection<T>, return ICollection<T>
  instead of the concrete type

As a consequence of useCollection, method imputs will also change to
Collection<T>.
@jimschubert jimschubert force-pushed the csharp_List_to_ICollection branch from 696d74a to 9dc4012 Compare January 24, 2016 14:16
@jimschubert
Copy link
Contributor Author

@wing328 I've added two options: useCollection and returnICollection. I rebased my branch and merged master.

  • useCollection: Deserialize responses into and return Collection<T>
  • returnICollection: For List<T> or Collection<T>, return ICollection<T>
    instead of the concrete type

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2016

@jimschubert thanks for adding the option. I tested with useCollection only and got the following error:

screen shot 2016-01-25 at 10 12 49 am

But when I tested witih both useCollection and returnICollection set to true, I didn't get the error.

@jimschubert
Copy link
Contributor Author

@wing328 I don't know why that would happen. Commented on the line above which includes the import.

I noticed that any time I changed the resources, I had to run mvn clean package before generating the sample. I didn't get a chance to look into why.

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2016

Forgot to mention that the error I got is in Pet.cs (model.mustache) and I don't see System.Collections.ObjectModel hardcoded in model.mustache.

@jimschubert
Copy link
Contributor Author

Ah. That's weird. I can update the model template tomorrow. I can also rebase.

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2016

Thank you 🍺

@jimschubert jimschubert force-pushed the csharp_List_to_ICollection branch from df95d69 to b4eed0d Compare January 25, 2016 04:03
@jimschubert
Copy link
Contributor Author

@wing328 I've added that using directive to model.mustache. Looked like my config was only testing both options. Sorry about that. Couldn't rebase all commits because of the merge from master, but everything on my branch is now up to date.

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2016

@jimschubert no problem bro. I'll give it another try later and merge into master accordingly.

wing328 added a commit that referenced this pull request Jan 25, 2016
[csharp] Return ICollection<T> instead of List<T>
@wing328 wing328 merged commit 9e5e9cb into swagger-api:master Jan 25, 2016
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.

2 participants