Skip to content

Commit 3decf9f

Browse files
Merge pull request #224 from nextcloud/fix/scopes/correctly-merge-full-scope
fix(scopes): Correctly merge full scopes if multiple operations with the same path belong to different scopes
2 parents 01fe008 + 3688015 commit 3decf9f

File tree

6 files changed

+392
-1
lines changed

6 files changed

+392
-1
lines changed

generate-spec.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,16 @@
966966
}
967967

968968
if ($scope === 'full') {
969-
$openapiScope['paths'] = array_merge(...$fullScopePathArrays);
969+
foreach ($fullScopePathArrays as $fullScopePaths) {
970+
foreach ($fullScopePaths as $fullScopePath => $operations) {
971+
$openapiScope['paths'][$fullScopePath] ??= [];
972+
foreach ($operations as $method => $operation) {
973+
// Don't need to check if we overwrite an existing operation,
974+
// as we already check for collisions when validating the routes.
975+
$openapiScope['paths'][$fullScopePath][$method] = $operation;
976+
}
977+
}
978+
}
970979
$openapiScope['components']['schemas'] = $schemas;
971980
} else {
972981
$usedRefs = [];

tests/appinfo/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@
8383
['name' => 'Settings#deprecatedParameterGet', 'url' => '/api/{apiVersion}/deprecated-parameter-get', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
8484
['name' => 'Settings#deprecatedRouteAndParameter', 'url' => '/api/{apiVersion}/deprecated-route-parameter', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
8585
['name' => 'Settings#deprecatedRouteAndParameterGet', 'url' => '/api/{apiVersion}/deprecated-route-parameter-get', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
86+
['name' => 'Settings#samePathGet', 'url' => '/api/{apiVersion}/same-path', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
87+
['name' => 'Settings#samePathPost', 'url' => '/api/{apiVersion}/same-path', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
8688
],
8789
];

tests/lib/Controller/SettingsController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,28 @@ public function deprecatedRouteAndParameter(bool $active, bool $deprecated): Dat
715715
public function deprecatedRouteAndParameterGet(bool $active, bool $deprecated): DataResponse {
716716
return new DataResponse();
717717
}
718+
719+
/**
720+
* A GET method with the same path as the POST method
721+
*
722+
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
723+
*
724+
* 200: Admin settings updated
725+
*/
726+
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
727+
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
728+
public function samePathGet(): DataResponse {
729+
return new DataResponse();
730+
}
731+
732+
/**
733+
* A POST method with the same path as the GET method
734+
*
735+
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
736+
*
737+
* 200: Admin settings updated
738+
*/
739+
public function samePathPost(): DataResponse {
740+
return new DataResponse();
741+
}
718742
}

tests/openapi-administration.json

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,6 +5210,148 @@
52105210
}
52115211
}
52125212
},
5213+
"/ocs/v2.php/apps/notifications/api/{apiVersion}/same-path": {
5214+
"get": {
5215+
"operationId": "settings-same-path-get",
5216+
"summary": "A GET method with the same path as the POST method",
5217+
"description": "This endpoint requires admin access",
5218+
"tags": [
5219+
"settings"
5220+
],
5221+
"security": [
5222+
{
5223+
"bearer_auth": []
5224+
},
5225+
{
5226+
"basic_auth": []
5227+
}
5228+
],
5229+
"parameters": [
5230+
{
5231+
"name": "apiVersion",
5232+
"in": "path",
5233+
"required": true,
5234+
"schema": {
5235+
"type": "string",
5236+
"enum": [
5237+
"v2"
5238+
],
5239+
"default": "v2"
5240+
}
5241+
},
5242+
{
5243+
"name": "OCS-APIRequest",
5244+
"in": "header",
5245+
"description": "Required to be true for the API request to pass",
5246+
"required": true,
5247+
"schema": {
5248+
"type": "boolean",
5249+
"default": true
5250+
}
5251+
}
5252+
],
5253+
"responses": {
5254+
"200": {
5255+
"description": "Admin settings updated",
5256+
"content": {
5257+
"application/json": {
5258+
"schema": {
5259+
"type": "object",
5260+
"required": [
5261+
"ocs"
5262+
],
5263+
"properties": {
5264+
"ocs": {
5265+
"type": "object",
5266+
"required": [
5267+
"meta",
5268+
"data"
5269+
],
5270+
"properties": {
5271+
"meta": {
5272+
"$ref": "#/components/schemas/OCSMeta"
5273+
},
5274+
"data": {}
5275+
}
5276+
}
5277+
}
5278+
}
5279+
}
5280+
}
5281+
}
5282+
}
5283+
},
5284+
"post": {
5285+
"operationId": "settings-same-path-post",
5286+
"summary": "A POST method with the same path as the GET method",
5287+
"description": "This endpoint requires admin access",
5288+
"tags": [
5289+
"settings"
5290+
],
5291+
"security": [
5292+
{
5293+
"bearer_auth": []
5294+
},
5295+
{
5296+
"basic_auth": []
5297+
}
5298+
],
5299+
"parameters": [
5300+
{
5301+
"name": "apiVersion",
5302+
"in": "path",
5303+
"required": true,
5304+
"schema": {
5305+
"type": "string",
5306+
"enum": [
5307+
"v2"
5308+
],
5309+
"default": "v2"
5310+
}
5311+
},
5312+
{
5313+
"name": "OCS-APIRequest",
5314+
"in": "header",
5315+
"description": "Required to be true for the API request to pass",
5316+
"required": true,
5317+
"schema": {
5318+
"type": "boolean",
5319+
"default": true
5320+
}
5321+
}
5322+
],
5323+
"responses": {
5324+
"200": {
5325+
"description": "Admin settings updated",
5326+
"content": {
5327+
"application/json": {
5328+
"schema": {
5329+
"type": "object",
5330+
"required": [
5331+
"ocs"
5332+
],
5333+
"properties": {
5334+
"ocs": {
5335+
"type": "object",
5336+
"required": [
5337+
"meta",
5338+
"data"
5339+
],
5340+
"properties": {
5341+
"meta": {
5342+
"$ref": "#/components/schemas/OCSMeta"
5343+
},
5344+
"data": {}
5345+
}
5346+
}
5347+
}
5348+
}
5349+
}
5350+
}
5351+
}
5352+
}
5353+
}
5354+
},
52135355
"/ocs/v2.php/tests/attribute-ocs/{param}": {
52145356
"get": {
52155357
"operationId": "routing-attributeocs-route",

tests/openapi-federation.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,78 @@
156156
}
157157
}
158158
}
159+
},
160+
"/ocs/v2.php/apps/notifications/api/{apiVersion}/same-path": {
161+
"get": {
162+
"operationId": "settings-same-path-get",
163+
"summary": "A GET method with the same path as the POST method",
164+
"description": "This endpoint requires admin access",
165+
"tags": [
166+
"settings"
167+
],
168+
"security": [
169+
{
170+
"bearer_auth": []
171+
},
172+
{
173+
"basic_auth": []
174+
}
175+
],
176+
"parameters": [
177+
{
178+
"name": "apiVersion",
179+
"in": "path",
180+
"required": true,
181+
"schema": {
182+
"type": "string",
183+
"enum": [
184+
"v2"
185+
],
186+
"default": "v2"
187+
}
188+
},
189+
{
190+
"name": "OCS-APIRequest",
191+
"in": "header",
192+
"description": "Required to be true for the API request to pass",
193+
"required": true,
194+
"schema": {
195+
"type": "boolean",
196+
"default": true
197+
}
198+
}
199+
],
200+
"responses": {
201+
"200": {
202+
"description": "Admin settings updated",
203+
"content": {
204+
"application/json": {
205+
"schema": {
206+
"type": "object",
207+
"required": [
208+
"ocs"
209+
],
210+
"properties": {
211+
"ocs": {
212+
"type": "object",
213+
"required": [
214+
"meta",
215+
"data"
216+
],
217+
"properties": {
218+
"meta": {
219+
"$ref": "#/components/schemas/OCSMeta"
220+
},
221+
"data": {}
222+
}
223+
}
224+
}
225+
}
226+
}
227+
}
228+
}
229+
}
230+
}
159231
}
160232
},
161233
"tags": []

0 commit comments

Comments
 (0)