@@ -34,17 +34,22 @@ private function docsToOpenApi(array $docs): void
34
34
{
35
35
$ this ->openApi ['paths ' ] = [];
36
36
foreach ($ docs as $ doc ) {
37
- $ requestHasFile = false ;
38
- $ httpMethod = strtolower ($ doc ->getHttpMethod ());
39
- $ isGet = $ httpMethod == 'get ' ;
40
- $ isPost = $ httpMethod == 'post ' ;
41
- $ isPut = $ httpMethod == 'put ' ;
42
- $ isDelete = $ httpMethod == 'delete ' ;
43
-
44
- $ this ->openApi ['paths ' ][$ doc ->getUri ()][$ httpMethod ]['description ' ] = $ doc ->getDocBlock ();
45
- $ this ->openApi ['paths ' ][$ doc ->getUri ()][$ httpMethod ]['parameters ' ] = [];
37
+ $ requestHasFile = false ;
38
+ $ httpMethod = strtolower ($ doc ->getHttpMethod ());
39
+ $ isGet = $ httpMethod == 'get ' ;
40
+ $ isPost = $ httpMethod == 'post ' ;
41
+ $ isPut = $ httpMethod == 'put ' ;
42
+ $ isDelete = $ httpMethod == 'delete ' ;
43
+ $ uriLeadingSlash = '/ ' . $ doc ->getUri ();
44
+
45
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['description ' ] = $ doc ->getDocBlock ();
46
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ] = [];
47
+
48
+ foreach ($ doc ->getPathParameters () as $ parameter => $ rule ) {
49
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ this ->makeQueryParameterItem ($ parameter , $ rule );
50
+ }
46
51
47
- $ this ->openApi ['paths ' ][$ doc -> getUri () ][$ httpMethod ]['responses ' ] = config ('request-docs.open_api.responses ' , []);
52
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['responses ' ] = config ('request-docs.open_api.responses ' , []);
48
53
49
54
foreach ($ doc ->getRules () as $ attribute => $ rules ) {
50
55
foreach ($ rules as $ rule ) {
@@ -60,21 +65,18 @@ private function docsToOpenApi(array $docs): void
60
65
61
66
$ contentType = $ requestHasFile ? 'multipart/form-data ' : 'application/json ' ;
62
67
63
- if ($ isGet ) {
64
- $ this ->openApi ['paths ' ][$ doc ->getUri ()][$ httpMethod ]['parameters ' ] = [];
65
- }
66
68
if ($ isPost || $ isPut || $ isDelete ) {
67
- $ this ->openApi ['paths ' ][$ doc -> getUri () ][$ httpMethod ]['requestBody ' ] = $ this ->makeRequestBodyItem ($ contentType );
69
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ] = $ this ->makeRequestBodyItem ($ contentType );
68
70
}
69
71
70
72
foreach ($ doc ->getRules () as $ attribute => $ rules ) {
71
73
foreach ($ rules as $ rule ) {
72
74
if ($ isGet ) {
73
- $ parameter = $ this ->makeQueryParameterItem ($ attribute , $ rule );
74
- $ this ->openApi ['paths ' ][$ doc -> getUri () ][$ httpMethod ]['parameters ' ][] = $ parameter ;
75
+ $ parameter = $ this ->makeQueryParameterItem ($ attribute , $ rule );
76
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ parameter ;
75
77
}
76
78
if ($ isPost || $ isPut || $ isDelete ) {
77
- $ this ->openApi ['paths ' ][$ doc -> getUri () ][$ httpMethod ]['requestBody ' ]['content ' ][$ contentType ]['schema ' ]['properties ' ][$ attribute ] = $ this ->makeRequestBodyContentPropertyItem ($ rule );
79
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ]['content ' ][$ contentType ]['schema ' ]['properties ' ][$ attribute ] = $ this ->makeRequestBodyContentPropertyItem ($ rule );
78
80
}
79
81
}
80
82
}
0 commit comments