Skip to content

Commit

Permalink
Merge pull request #76 from nextcloud/fix/openapitype/deduplicate-enums
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Jan 17, 2024
2 parents 9128afa + f9b8419 commit 3fb48b2
Show file tree
Hide file tree
Showing 4 changed files with 591 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ private static function mergeEnums(array $types): array {
}
}

foreach (array_map(static fn (OpenApiType $type) => $type->type, $nonEnums) as $type) {
if (array_key_exists($type, $enums)) {
unset($enums[$type]);
}
}

return array_merge($nonEnums, array_map(fn (string $type) => new OpenApiType(type: $type, enum: $enums[$type]), array_keys($enums)));
}

Expand Down
10 changes: 8 additions & 2 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@
['name' => 'Settings#listOfIntStringAndOneBool', 'url' => '/api/{apiVersion}/mixed-list-one', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#listOfIntStringAndAllBools', 'url' => '/api/{apiVersion}/mixed-list-all', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanParameterRequired', 'url' => '/api/{apiVersion}/boolean', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanParameterDefaultFalse', 'url' => '/api/{apiVersion}/boolean-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanParameterDefaultTrue', 'url' => '/api/{apiVersion}/boolean-true', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanParameterDefaultFalse', 'url' => '/api/{apiVersion}/boolean-default-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanParameterDefaultTrue', 'url' => '/api/{apiVersion}/boolean-default-true', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanTrueParameter', 'url' => '/api/{apiVersion}/boolean-true', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanFalseParameter', 'url' => '/api/{apiVersion}/boolean-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#booleanTrueFalseParameter', 'url' => '/api/{apiVersion}/boolean-true-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#trueFalseParameter', 'url' => '/api/{apiVersion}/true-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#stringValueParameter', 'url' => '/api/{apiVersion}/string-value', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#intValueParameter', 'url' => '/api/{apiVersion}/int-value', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#numericParameter', 'url' => '/api/{apiVersion}/numeric', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
72 changes: 72 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,78 @@ public function booleanParameterDefaultTrue(bool $yesOrNo = true): DataResponse
return new DataResponse();
}

/**
* A route with boolean or true
*
* @param bool|true $yesOrNo boolean or true
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function booleanTrueParameter(bool $yesOrNo): DataResponse {
return new DataResponse();
}

/**
* A route with boolean or false
*
* @param bool|false $yesOrNo boolean or false
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function booleanFalseParameter(bool $yesOrNo): DataResponse {
return new DataResponse();
}

/**
* A route with boolean or true or false
*
* @param bool|true|false $yesOrNo boolean or true or false
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function booleanTrueFalseParameter(bool $yesOrNo): DataResponse {
return new DataResponse();
}

/**
* A route with true or false
*
* @param true|false $yesOrNo true or false
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function trueFalseParameter(bool $yesOrNo): DataResponse {
return new DataResponse();
}

/**
* A route with string or 'test'
*
* @param string|'test' $value string or 'test'
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function stringValueParameter(string $value): DataResponse {
return new DataResponse();
}

/**
* A route with int or 0
*
* @param int|0 $value int or 0
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
public function intValueParameter(int $value): DataResponse {
return new DataResponse();
}

/**
* A route with numeric
*
Expand Down
Loading

0 comments on commit 3fb48b2

Please sign in to comment.