@@ -40,3 +40,40 @@ func TestSpec_SetOperation(t *testing.T) {
4040 assert .EqualError (t , s .AddOperation (http .MethodGet , "/another/{foo}" , op ),
4141 "duplicate parameter in path: foo, duplicate parameter in query: bar" )
4242}
43+
44+ func TestSpec_SetupOperation_pathRegex (t * testing.T ) {
45+ s := openapi3.Spec {}
46+
47+ for _ , tc := range []struct {
48+ path string
49+ params []string
50+ }{
51+ {`/{month}-{day}-{year}` , []string {"month" , "day" , "year" }},
52+ {`/{month}/{day}/{year}` , []string {"month" , "day" , "year" }},
53+ {`/{month:[\d]+}-{day:[\d]+}-{year:[\d]+}` , []string {"month" , "day" , "year" }},
54+ {`/{articleSlug:[a-z-]+}` , []string {"articleSlug" }},
55+ {"/articles/{rid:^[0-9]{5,6}}" , []string {"rid" }},
56+ {"/articles/{rid:^[0-9]{5,6}}/{zid:^[0-9]{5,6}}" , []string {"rid" , "zid" }},
57+ {"/articles/{zid:^0[0-9]+}" , []string {"zid" }},
58+ {"/articles/{name:^@[a-z]+}/posts" , []string {"name" }},
59+ {"/articles/{op:^[0-9]+}/run" , []string {"op" }},
60+ {"/users/{userID:[^/]+}" , []string {"userID" }},
61+ {"/users/{userID:[^/]+}/books/{bookID:.+}" , []string {"userID" , "bookID" }},
62+ } {
63+ t .Run (tc .path , func (t * testing.T ) {
64+ assert .NoError (t , s .SetupOperation (http .MethodGet , tc .path ,
65+ func (operation * openapi3.Operation ) error {
66+ var pp []openapi3.ParameterOrRef
67+
68+ for _ , p := range tc .params {
69+ pp = append (pp , openapi3.Parameter {In : openapi3 .ParameterInPath , Name : p }.ToParameterOrRef ())
70+ }
71+
72+ operation .WithParameters (pp ... )
73+
74+ return nil
75+ },
76+ ))
77+ })
78+ }
79+ }
0 commit comments