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

[ISSUE-287] GetQueriesTemplates and GetQueriesRegexp extraction #304

Merged
merged 1 commit into from
Oct 20, 2017

Conversation

paulbes
Copy link
Contributor

@paulbes paulbes commented Oct 11, 2017

Developers can now extract the query templates and regexps from a router as lists of combined query pairs.

Description

The implementation returns lists of combined pairs of registered Queries; as templates or regexps. It was deemed more appropriate to return lists, at least for regexps, rather than a joined string of all combined pairs, since each query pair is considered a separate matcher, e.g., if we have the following: Queries("foo", "{v1}", "baz", "{v2}"), when joined using regexps we would end up with: ^foo=(?P<v0>.*)$,^baz=(?P<v0>.*)$. The multiple v0 entries might be confusing. For the query template, we could consider joining, but even then it will be a bit strange, e.g., foo={v1},baz={v2}.

Motivation and Context

Being able to extract all parts of a registered route, including queries, can be very useful. In particular when generating REST API documentation. In addition, it can be useful to determine that tests have been written for all registered routes; by matching recorded and registered routes with their various parts.

How Has This Been Tested (if appropriate)?

Added testQueriesRegexp and testQueriesTemplates methods and added queriesTemplate and queriesRegexp fields to routeTest. All TestQueries cases are using this functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (non-breaking changes, no bug fixing, no new features)
  • Testing (New unit/integration/performance tests)

Checklist:

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Related tickets or issues:

This resolves issue #287

Developers can now extract the query templates and regexps
from a router as lists of combined query pairs.
@paulbes paulbes changed the title GetQueryTemplates and GetQueryRegexp extraction [ISSUE-287] GetQueryTemplates and GetQueryRegexp extraction Oct 11, 2017
@paulbes paulbes changed the title [ISSUE-287] GetQueryTemplates and GetQueryRegexp extraction [ISSUE-287] GetQueriesTemplates and GetQueriesRegexp extraction Oct 11, 2017
@elithrar
Copy link
Contributor

elithrar commented Oct 11, 2017 via email

@kisielk
Copy link
Contributor

kisielk commented Oct 11, 2017

Is there a reason you'd want just the Regexp or just the templates? Is there value in it being two separate functions?

@paulbes
Copy link
Contributor Author

paulbes commented Oct 12, 2017

I can't speak for all use-cases, but we will end up using GetQueriesTemplates primarily, I added the GetQueriesRegexp for completeness primarily; there being an equivalent one for Path. I am not sure when it would be used, perhaps in use-cases where a developer wants to examine the final regexp that is being matched with by mux.

Are you considering merging them into one or dropping either? If merging, what would this look like?

@paulbes
Copy link
Contributor Author

paulbes commented Oct 18, 2017

Do we need to make any changes to this PR or should it be merged?

@elithrar
Copy link
Contributor

If @kisielk is OK with the API here then it’s OK to merge.

@kisielk kisielk merged commit 10490f5 into gorilla:master Oct 20, 2017
@kisielk
Copy link
Contributor

kisielk commented Oct 20, 2017

The symmetry with the GetPathXXX methods makes sense. Sorry I missed the last email update. Thanks for the patch!

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