NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.46k forks source link

IsParameterized and GetParameterDetails don't work with route segment constraints #2709

Open jonorossi opened 7 years ago

jonorossi commented 7 years ago

The following two Nancy extension methods use a regex that doesn't support route segment constraints (e.g. {id:int}):

The regex supports curly segments with a name, then an optional default prefixed by ?:

It appears the Nancy codebase doesn't use either nor does it use the ParameterSegmentInformation class, I'm not sure if the regex should be fixed or if this is just obsolete code that hasn't been removed yet.

I'm attempting to use these functions to add path parameters to automatically generated documentation, I'd prefer to use the actual parsing code and I'd love to get instances of IRouteSegmentConstraint but that doesn't seem possible without a URL.

Steps to Reproduce

Looking at the unit tests there are the following cases:

"route".IsParameterized().ShouldBeFalse();
"{param}".IsParameterized().ShouldBeTrue();
"".IsParameterized().ShouldBeFalse();

While something like this will fail:

"{param:int}".IsParameterized().ShouldBeTrue();

System Configuration

The regex and extension methods are unchanged between 1.x-WorkingBranch and master.

thecodejunkie commented 7 years ago

@phillip-haydon you did work on the {params:xxxxx} stuff, care to look at this?