-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
#1107 Do no set default visibility and affiliation values to avoid mixing with type #1132
#1107 Do no set default visibility and affiliation values to avoid mixing with type #1132
Conversation
LGTM, but I would say there should be a check/manual set to default for the |
With this change, won't there still be an issue if you set a non So you'd either have to add your eg public class RepositoryRequest : RequestParameters
{
public RepositoryType? Type { get; set; }
public RepositorySort? Sort { get; set; }
public SortDirection? Direction { get; set; }
public RepositoryVisibility? Visibility { get; set; }
public RepositoryAffiliation? Affiliation { get; set; }
} Whichever way it's done, I agree with @M-Zuber it would be useful to check the
Perhaps @shiftkey can advise between the preference of adding a Also when I'm adding functionality to Octokit, I always try to add tests as well, so that from now on we can assert that this problem never re-appears down the track. In this case I would add unit tests to cover:
|
I'd rather these be optional parameters as that's the precedence we have for handling values that may be set. And as per the docs, there's documented default behaviour here for all these values if they're not set: I have some concerns that I should have raised earlier. Consider this scenario: var request = new RepositoryRequest
{
Visibility = RepositoryVisibility.Public,
Type = RepositoryType.Owner
}; This is a valid object to create, however it will fail during the request. Do we guard against that, or just bubble up the exception to the user? There's an escape hatch we have to override Anyway, 👍 to throwing more unit tests into this area - |
I made the properties nullable instead of Default enum parameters and added unit tests for RepositoryRequest ToParamatersDictionary. |
@@ -49,6 +49,9 @@ static List<PropertyParameter> GetPropertyParametersForType(Type type) | |||
Justification = "GitHub API depends on lower case strings")] | |||
static Func<PropertyInfo, object, string> GetValueFunc(Type propertyType) | |||
{ | |||
// get underlying type if nullable | |||
propertyType = Nullable.GetUnderlyingType(propertyType) ?? propertyType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary? The parameter array was still created correctly for me, even without this line...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this line it does not go into if (propertyType.IsEnumeration())
and somehow produces "All" instead of "all" + does not use [Parameter]
attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah fair enough, I must admit I just quickly put the nullable properties on the request object and ran the existing integration tests which passed... From what you're saying we might need more tests since the current ones didn't pick up the problem you highlighted... oops, obviously I don't have your new test which looks like it covers those scenarios 😀
Nice work on the parameter array unit test :) While we're here I wonder if we should tweak the |
Yeah, I was thinking about For null values, shoud we output something like |
I think the way you've done it is good (if the values are null, don't mention them at all). LGTM - I'll just wait for a +1 from @shiftkey before merging |
Looks good to me! Thanks @AlexP11223! And thanks @M-Zuber @ryangribble for helping out with the review! |
…lation-mix-1107 #1107 Do no set default visibility and affiliation values to avoid mixing with type
An attempt to fix mixing of visibility/affiliation and type described in #1107.