Skip to content

Commit

Permalink
Merge pull request #150 from nextcloud/fix/openapitype/default-object…
Browse files Browse the repository at this point in the history
…-values
  • Loading branch information
provokateurin authored Aug 5, 2024
2 parents 46061fc + 46b1cf0 commit cdfedf4
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ enum: [0, 1],
$values["nullable"] = true;
}
if ($this->hasDefaultValue && $this->defaultValue !== null) {
$values["default"] = $this->defaultValue;
if ($this->type === 'object' && empty($this->defaultValue)) {
$values["default"] = new stdClass();
} else {
$values["default"] = $this->defaultValue;
}
}
if ($this->enum !== null) {
$values["enum"] = $this->enum;
Expand Down
1 change: 1 addition & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@
['name' => 'Settings#parameterRequestBody', 'url' => '/api/{apiVersion}/parameterPUT', 'verb' => 'PUT', 'postfix' => 'PUT', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#parameterRequestBody', 'url' => '/api/{apiVersion}/parameterDELETE', 'verb' => 'DELETE', 'postfix' => 'DELETE', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#parameterRequestBody', 'url' => '/api/{apiVersion}/parameterPATCH', 'verb' => 'PATCH', 'postfix' => 'PATCH', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#objectDefaults', 'url' => '/api/{apiVersion}/objectDefaults', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
15 changes: 15 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,19 @@ public function emptyArray(): DataResponse {
public function parameterRequestBody(int $simple, array $complex): DataResponse {
return new DataResponse();
}


/**
* Route with object defaults
*
* @param array<string, string> $empty Empty
* @param array<string, string> $values Values
* @return DataResponse<Http::STATUS_OK, array{test: array<empty>}, array{}>
*
* 200: OK
*/
#[PasswordConfirmationRequired]
public function objectDefaults(array $empty = [], array $values = ['key' => 'value']): DataResponse {
return new DataResponse();
}
}
113 changes: 113 additions & 0 deletions tests/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,119 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/objectDefaults": {
"post": {
"operationId": "settings-object-defaults",
"summary": "Route with object defaults",
"description": "This endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"empty": {
"type": "object",
"default": {},
"description": "Empty",
"additionalProperties": {
"type": "string"
}
},
"values": {
"type": "object",
"default": {
"key": "value"
},
"description": "Values",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
},
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"test"
],
"properties": {
"test": {
"type": "array",
"maxItems": 0
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/tests/attribute-ocs/{param}": {
"get": {
"operationId": "routing-attributeocs-route",
Expand Down
113 changes: 113 additions & 0 deletions tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -4079,6 +4079,119 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/objectDefaults": {
"post": {
"operationId": "settings-object-defaults",
"summary": "Route with object defaults",
"description": "This endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"empty": {
"type": "object",
"default": {},
"description": "Empty",
"additionalProperties": {
"type": "string"
}
},
"values": {
"type": "object",
"default": {
"key": "value"
},
"description": "Values",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
},
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"test"
],
"properties": {
"test": {
"type": "array",
"maxItems": 0
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/tests/attribute-ocs/{param}": {
"get": {
"operationId": "routing-attributeocs-route",
Expand Down

0 comments on commit cdfedf4

Please sign in to comment.