Skip to content

Commit 4d1f8c6

Browse files
authored
Update SwaggerJson.php
修复同一method注解多路由文档生成bug
1 parent 5fecc51 commit 4d1f8c6

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

src/Swagger/SwaggerJson.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ public function addPath($className, $methodName, $path)
6868
$params = [];
6969
$responses = [];
7070
/** @var GetApi $mapping */
71-
$mapping = null;
71+
$mappings = [];
7272
$consumes = null;
7373
$rules = [];
7474
$consumes = 'application/x-www-form-urlencoded';
75+
76+
p($methodAnnotations);
7577
foreach ($methodAnnotations as $option) {
7678
if ($option instanceof RequestValidation) {
7779
$rules = array_merge($rules, $this->getValidateRule($option));
@@ -100,7 +102,7 @@ public function addPath($className, $methodName, $path)
100102
}
101103

102104
if ($option instanceof Mapping) {
103-
$mapping = $option;
105+
$mappings[] = $option;
104106
}
105107
if ($option instanceof Param) {
106108
$params[] = $option;
@@ -132,25 +134,26 @@ public function addPath($className, $methodName, $path)
132134
}
133135
$path = str_replace("/_self_path", "", $path);
134136
$path = $this->getPath($path);
135-
136-
$method = strtolower($mapping->methods[0] ?? '');
137-
$this->swagger['paths'][$path][$method] = [
138-
'tags' => [$tag],
139-
'summary' => $mapping->summary ?? '',
140-
'description' => $mapping->description ?? '',
141-
'operationId' => implode('', array_map('ucfirst', explode('/', $path))) . ($mapping->methods[0] ?? ''),
142-
'parameters' => $this->makeParameters($params, $path, $method),
143-
'produces' => [
144-
$consumes
145-
],
146-
'responses' => $this->makeResponses($responses, $path, $method),
147-
];
148-
if ($consumes !== null) {
149-
$this->swagger['paths'][$path][$method]['consumes'] = [$consumes];
150-
}
151-
if ($mapping && property_exists($mapping, 'security') && $mapping->security && isset($this->swagger['securityDefinitions'])) {
152-
foreach ($this->swagger['securityDefinitions'] as $key => $val) {
153-
$this->swagger['paths'][$path][$method]['security'][] = [$key => $val['petstore_auth'] ?? []];
137+
foreach ($mappings as $mapping){
138+
$method = strtolower($mapping->methods[0] ?? '');
139+
$this->swagger['paths'][$path][$method] = [
140+
'tags' => [$tag],
141+
'summary' => $mapping->summary ?? '',
142+
'description' => $mapping->description ?? '',
143+
'operationId' => implode('', array_map('ucfirst', explode('/', $path))) . ($mapping->methods[0] ?? ''),
144+
'parameters' => $this->makeParameters($params, $path, $method),
145+
'produces' => [
146+
$consumes
147+
],
148+
'responses' => $this->makeResponses($responses, $path, $method),
149+
];
150+
if ($consumes !== null) {
151+
$this->swagger['paths'][$path][$method]['consumes'] = [$consumes];
152+
}
153+
if ($mapping && property_exists($mapping, 'security') && $mapping->security && isset($this->swagger['securityDefinitions'])) {
154+
foreach ($this->swagger['securityDefinitions'] as $key => $val) {
155+
$this->swagger['paths'][$path][$method]['security'][] = [$key => $val['petstore_auth'] ?? []];
156+
}
154157
}
155158
}
156159
}

0 commit comments

Comments
 (0)