Implemented oneOf for non-array results with multiple types

This commit is contained in:
Matej Baco
2021-09-23 13:12:50 +02:00
parent 9c9a17a2a4
commit c97b153255
2 changed files with 27 additions and 10 deletions
+14 -5
View File
@@ -6,6 +6,7 @@ use Appwrite\Specification\Format;
use Appwrite\Template\Template;
use stdClass;
use Utopia\Validator;
use function var_dump;
class OpenAPI3 extends Format
{
@@ -442,11 +443,19 @@ class OpenAPI3 extends Format
$rule['type'] = ($rule['type']) ? $rule['type'] : 'none';
if(\is_array($rule['type'])) {
$items = [
'anyOf' => \array_map(function($type) {
return ['$ref' => '#/components/schemas/'.$type];
}, $rule['type'])
];
if($rule['array']) {
$items = [
'anyOf' => \array_map(function($type) {
return ['$ref' => '#/components/schemas/'.$type];
}, $rule['type'])
];
} else {
$items = [
'oneOf' => \array_map(function($type) {
return ['$ref' => '#/components/schemas/'.$type];
}, $rule['type'])
];
}
} else {
$items = [
'$ref' => '#/components/schemas/'.$rule['type'],
+13 -5
View File
@@ -445,11 +445,19 @@ class Swagger2 extends Format
$rule['type'] = ($rule['type']) ? $rule['type'] : 'none';
if(\is_array($rule['type'])) {
$items = [
'anyOf' => \array_map(function($type) {
return ['$ref' => '#/definitions/'.$type];
}, $rule['type'])
];
if($rule['array']) {
$items = [
'anyOf' => \array_map(function($type) {
return ['$ref' => '#/definitions/'.$type];
}, $rule['type'])
];
} else {
$items = [
'oneOf' => \array_map(function($type) {
return ['$ref' => '#/definitions/'.$type];
}, $rule['type'])
];
}
} else {
$items = [
'type' => $type,