This repository was archived by the owner on Jan 20, 2024. It is now read-only.
File tree 3 files changed +26
-4
lines changed
3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -844,7 +844,7 @@ public function getMatchPattern()
844
844
if ($ this ->validationPattern ) {
845
845
$ pattern = $ this ->validationPattern ;
846
846
} elseif ($ enum = $ this ->getEnum ()) {
847
- $ pattern = '^( ' . implode ('\ | ' , array_map ('preg_quote ' , $ enum )) . ')$ ' ;
847
+ $ pattern = '^( ' . implode ('| ' , array_map ('preg_quote ' , $ enum )) . ')$ ' ;
848
848
} else {
849
849
switch ($ this ->getType ()) {
850
850
case self ::TYPE_NUMBER :
Original file line number Diff line number Diff line change @@ -200,11 +200,11 @@ public function matchesUri($uri)
200
200
if ('^ ' === $ matchPattern [0 ]) {
201
201
$ matchPattern = substr ($ matchPattern , 1 );
202
202
}
203
-
203
+
204
204
if ('$ ' === substr ($ matchPattern , -1 )) {
205
205
$ matchPattern = substr ($ matchPattern , 0 , -1 );
206
206
}
207
-
207
+
208
208
$ regexUri = str_replace (
209
209
'/{ ' .$ uriParameter ->getKey ().'} ' ,
210
210
'/ ' .$ matchPattern ,
@@ -221,7 +221,7 @@ public function matchesUri($uri)
221
221
222
222
$ regexUri = preg_replace ('/\/{.*}/U ' , '\/([^/]+) ' , $ regexUri );
223
223
$ regexUri = preg_replace ('/\/~{.*}/U ' , '\/([^/]*) ' , $ regexUri );
224
- $ regexUri = ' |^ ' . $ regexUri . ' $| ' ;
224
+ $ regexUri = chr ( 128 ). ' ^ ' . $ regexUri. ' $ ' . chr ( 128 ) ;
225
225
226
226
return (bool ) preg_match ($ regexUri , $ uri );
227
227
}
Original file line number Diff line number Diff line change @@ -60,4 +60,26 @@ public function shouldCorrectlyParseRegexUriParameters()
60
60
$ resource = $ apiDef ->getResourceByUri ('/user/alec ' );
61
61
$ this ->assertInstanceOf ('\Raml\Resource ' , $ resource );
62
62
}
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
+ }
63
85
}
You can’t perform that action at this time.
0 commit comments