This repository was archived by the owner on Jan 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed
Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -844,7 +844,7 @@ public function getMatchPattern()
844844 if ($ this ->validationPattern ) {
845845 $ pattern = $ this ->validationPattern ;
846846 } elseif ($ enum = $ this ->getEnum ()) {
847- $ pattern = '^( ' . implode ('\ | ' , array_map ('preg_quote ' , $ enum )) . ')$ ' ;
847+ $ pattern = '^( ' . implode ('| ' , array_map ('preg_quote ' , $ enum )) . ')$ ' ;
848848 } else {
849849 switch ($ this ->getType ()) {
850850 case self ::TYPE_NUMBER :
Original file line number Diff line number Diff line change @@ -200,11 +200,11 @@ public function matchesUri($uri)
200200 if ('^ ' === $ matchPattern [0 ]) {
201201 $ matchPattern = substr ($ matchPattern , 1 );
202202 }
203-
203+
204204 if ('$ ' === substr ($ matchPattern , -1 )) {
205205 $ matchPattern = substr ($ matchPattern , 0 , -1 );
206206 }
207-
207+
208208 $ regexUri = str_replace (
209209 '/{ ' .$ uriParameter ->getKey ().'} ' ,
210210 '/ ' .$ matchPattern ,
@@ -221,7 +221,7 @@ public function matchesUri($uri)
221221
222222 $ regexUri = preg_replace ('/\/{.*}/U ' , '\/([^/]+) ' , $ regexUri );
223223 $ regexUri = preg_replace ('/\/~{.*}/U ' , '\/([^/]*) ' , $ regexUri );
224- $ regexUri = ' |^ ' . $ regexUri . ' $| ' ;
224+ $ regexUri = chr ( 128 ). ' ^ ' . $ regexUri. ' $ ' . chr ( 128 ) ;
225225
226226 return (bool ) preg_match ($ regexUri , $ uri );
227227 }
Original file line number Diff line number Diff line change @@ -60,4 +60,26 @@ public function shouldCorrectlyParseRegexUriParameters()
6060 $ resource = $ apiDef ->getResourceByUri ('/user/alec ' );
6161 $ this ->assertInstanceOf ('\Raml\Resource ' , $ resource );
6262 }
63+
64+ /** @test */
65+ public function shouldCorrectlyParseEnumUriParameters ()
66+ {
67+ $ raml = <<<RAML
68+ #%RAML 0.8
69+ title: User API
70+ version: 1.2
71+ /user:
72+ /{userName}:
73+ displayName: Get a user by name
74+ uriParameters:
75+ userName:
76+ enum: [one, two]
77+ get:
78+ displayName: retrieve a user's picture by user name
79+ RAML ;
80+
81+ $ apiDef = $ this ->parser ->parseFromString ($ raml , '' );
82+ $ resource = $ apiDef ->getResourceByUri ('/user/one ' );
83+ $ this ->assertInstanceOf ('\Raml\Resource ' , $ resource );
84+ }
6385}
You can’t perform that action at this time.
0 commit comments