Allowing hyphens in Query Params
See original GitHub issueI have a query param that has a hyphen as the key. e.g. foo-bar
, but dredd is throwing an error that it’s invalid.
For example:
## Things [/things{?widget-type}]
+ Parameters
+ `widget-type`: wonky (string)
But when I run dredd, I get:
error: Runtime compilation error:
Failed to parse URI template: /things{?widget-type}
Error: SyntaxError: Expected "(", "*", ",", ":", "}" or [a-zA-Z0-9_.%] but "-" found.
on > Things > widget-type
error: Error parsing ast to blueprint.
I haven’t see any specs that prohibit -
Looks like the source is https://github.com/grncdr/uri-template/issues/14
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Can hyphens be used in query string values? - Stack Overflow
yes hyphens can be used . only characters can reliably use for the actual name parts of a URL are a-z, A-Z, 0-9,...
Read more >Dash (Hyphen) or Underscore in URLs: Which one to use and ...
A simple Google search for “dash vs underscore” will give you articles that clearly favor dashes (also called hyphens) and tell you to...
Read more >URLs: Should I use hyphens, underscores or plus symbols?
In short - Google views hyphens as word separators in a URL, making it much easier for Google to identify words and figure...
Read more >SEO best practice: Underscores or Hyphens in URLs?
Google views hyphens in URLs as word separators while an underscore in your url will not be recognized. This means using hyphens makes...
Read more >Google URL Structure Guidelines | Documentation
Consider using hyphens to separate words in your URLs, as it helps users and search engines identify concepts in the URL more easily....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@honzajavorek Thanks, for the help… I just tried to escape the value but not the key. Escaping on both sides works fine!
Sorry for activating this long ago closed discussion but it’s really important for integrating Dredd into our api validation process. We have dozens of microservices which have parameters which contain hyphens in their names and we can’t use Dredd because of this limitation. Btw swagger editor normally accepts those apis as completely valid schemas (screenshot is attached). I did some research and came across different articles in the internet which declare hyphen as a valid query parameter character and looks like it’s widely used, e.g. https://en.wikipedia.org/wiki/Query_string https://developers.google.com/maps/url-encoding https://www.oreilly.com/library/view/restful-web-services/9780596809140/ch04.html https://stackoverflow.com/questions/32348875/can-hyphens-be-used-in-query-string-values https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
Moreover it is highly encouraged to use hyphens instead of underscores when designing URI : https://developers.google.com/search/docs/advanced/guidelines/url-structure#:~:text=We recommend that you use,( _ ) in your URLs
I understand that you are trying to stick with rfc6570 but probably few follow the rules. Is it possible to replace this exception with warning? Or may be add some option/config to switch between interpretation of this rule as warning or error?