Skip to content

Commit c8c8fc5

Browse files
committed
improved requirement string generation algorithm
1 parent 48020e7 commit c8c8fc5

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

app/helpers/Swagger/AnnotationData.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,15 @@ private function getBodyAnnotation(): string | null
8383
foreach ($this->bodyParams as $bodyParam) {
8484
$body->addValue($bodyParam->toPropertyAnnotation());
8585
if ($bodyParam->required) {
86-
$required[] = $bodyParam->name;
86+
// add quotes around the names (required by the swagger generator)
87+
$required[] = '"' . $bodyParam->name . '"';
8788
}
8889
}
8990

9091
// add a list of required properties
9192
if (count($required) > 0) {
9293
// stringify the list (it has to be in '{"name1","name1",...}' format)
93-
$requiredString = "{";
94-
foreach ($required as $name) {
95-
$requiredString .= "\"$name\",";
96-
}
97-
$requiredString .= "}";
98-
94+
$requiredString = "{" . implode(",", $required) . "}";
9995
$body->addValue("required=" . $requiredString);
10096
}
10197

app/helpers/Swagger/ParameterConstraints.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ParameterConstraints
1616
*/
1717
public function __construct(?string $pattern = null, ?int $minLength = null, ?int $maxLength = null)
1818
{
19-
# swagger patterns must not contain the bounding '/.../' slashes
19+
// swagger patterns must not contain the bounding '/.../' slashes
2020
if ($pattern != null && strlen($pattern) >= 2) {
2121
$pattern = substr($pattern, 1, -1);
2222
}

0 commit comments

Comments
 (0)