1
0
Fork 0
mirror of synced 2024-05-20 04:32:37 +12:00

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

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'],

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,