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

Add more preferences for configuring openapi search paths #424

Merged
merged 2 commits into from
Nov 2, 2020

Conversation

tlmii
Copy link
Member

@tlmii tlmii commented Oct 29, 2020

Resolves #360.

Adds two additional preferences:

  • swagger.addToSearchPaths (adds the specified paths to the default list)
  • swagger.removeFromSearchPaths (removes the specified paths from the default list if they exist)

and configures the original available preference (swagger.searchPaths) to override both the default list and the two new preferences.

@tlmii tlmii requested review from jimmylewis and bzhu94 October 29, 2020 07:41
{
_preferences = preferences ?? throw new ArgumentNullException(nameof(preferences));
_ = preferences ?? throw new ArgumentNullException(nameof(preferences));
Copy link

Choose a reason for hiding this comment

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

This looks a little funky, though I understand the intent. Maybe put the ArgumentNullException check in the ctor of OpenApiSearchPathsProvider instead where it's actually used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming the "looks a little funky" was in reference to using the discard. According to Jimmy, it saves a few ops!

But yeah, since I also changed it to not store the value anymore and just pass it, moving it makes sense. Done.


namespace Microsoft.HttpRepl.Preferences
{
internal class OpenApiSearchPathsProvider : IOpenApiSearchPathsProvider
Copy link

Choose a reason for hiding this comment

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

Nit: sealed?

return DefaultSearchPaths.Union(addToSearchPaths).Except(removeFromSearchPaths);
}

private static string[] Split(string searchPaths)
Copy link

Choose a reason for hiding this comment

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

Is this function for exclusive use with search path preferences, or could it be useful for current other preferences or potential future ones down the line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a huge fan of pipe- (or frankly anything-) delimited strings, so I'm hoping there won't be too many of those before we get to a better settings system. I believe this is the only use case right now.


namespace Microsoft.HttpRepl.Fakes
{
public class FakePreferences : IPreferences
Copy link

Choose a reason for hiding this comment

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

Nit: sealed? :P

public FakePreferences()
{
DefaultPreferences = new Dictionary<string, string>();
_currentPreferences = new();
Copy link

Choose a reason for hiding this comment

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

What is this madness...Can you link me to this C# feature?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

@bzhu94 bzhu94 left a comment

Choose a reason for hiding this comment

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

Looks good!

@tlmii tlmii merged commit b537260 into dotnet:master Nov 2, 2020
@tlmii tlmii deleted the dev/more-search-path-config branch November 2, 2020 08:10
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.

Make well-known Open API description locations list more easily configurable
2 participants