Skip to content

Commit 8ded7e4

Browse files
committed
openapi path parameter object rules moving from query option
1 parent 09ae672 commit 8ded7e4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/LaravelRequestDocsToOpenApi.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
3333
private function docsToOpenApi(array $docs): void
3434
{
3535
$this->openApi['paths'] = [];
36+
// dd($docs);
3637
foreach ($docs as $doc) {
3738
$requestHasFile = false;
3839
$httpMethod = strtolower($doc->getHttpMethod());
@@ -46,7 +47,7 @@ private function docsToOpenApi(array $docs): void
4647
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['parameters'] = [];
4748

4849
foreach ($doc->getPathParameters() as $parameter => $rule) {
49-
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['parameters'][] = $this->makeQueryParameterItem($parameter, $rule);
50+
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['parameters'][] = $this->makePathParameterItem($parameter, $rule);
5051
}
5152

5253
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['responses'] = config('request-docs.open_api.responses', []);
@@ -106,6 +107,24 @@ protected function makeQueryParameterItem(string $attribute, $rule): array
106107
return $parameter;
107108
}
108109

110+
protected function makePathParameterItem(string $attribute, $rule): array
111+
{
112+
if (is_array($rule)) {
113+
$rule = implode('|', $rule);
114+
}
115+
$parameter = [
116+
'name' => $attribute,
117+
'description' => $rule,
118+
'in' => 'query',
119+
'style' => 'form',
120+
'required' => str_contains($rule, 'required'),
121+
'schema' => [
122+
'type' => $this->getAttributeType($rule),
123+
],
124+
];
125+
return $parameter;
126+
}
127+
109128
protected function makeRequestBodyItem(string $contentType): array
110129
{
111130
$requestBody = [

0 commit comments

Comments
 (0)