Skip to content

Commit

Permalink
Merge pull request #160 from nextcloud/fix/openapitype/clean-doc-comm…
Browse files Browse the repository at this point in the history
…ents

fix(OpenApiType): Clean whitespace in description fields
  • Loading branch information
nickvergessen authored Aug 23, 2024
2 parents ca93084 + 8cdd986 commit e8584a4
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Clean whitespace in description fields

## [1.0.0] - 2024-08-20

Expand Down
2 changes: 1 addition & 1 deletion src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ enum: [0, 1],
$values["enum"] = $this->enum;
}
if ($this->description !== null && $this->description !== "" && !$isParameter) {
$values["description"] = $this->description;
$values["description"] = Helpers::cleanDocComment($this->description);
}
if ($this->items !== null) {
$values["items"] = $this->items->toArray();
Expand Down
1 change: 1 addition & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@
['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)']],
['name' => 'Settings#whitespace', 'url' => '/api/{apiVersion}/whitespace', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
21 changes: 21 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,25 @@ public function parameterRequestBody(int $simple, array $complex): DataResponse
public function objectDefaults(array $empty = [], array $values = ['key' => 'value']): DataResponse {
return new DataResponse();
}

/**
* some
* whitespace
*
* even
* more
* whitespace
*
* @param int $value and this one
* has
* even
* more whitespace
* @return DataResponse<Http::STATUS_OK, array{test: array<empty>}, array{}>
*
* 200: OK
*/
#[PasswordConfirmationRequired]
public function whitespace(int $value): DataResponse {
return new DataResponse();
}
}
103 changes: 103 additions & 0 deletions tests/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -4050,6 +4050,109 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/whitespace": {
"post": {
"operationId": "settings-whitespace",
"summary": "some whitespace",
"description": "even more whitespace\nThis endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "integer",
"format": "int64",
"description": "and this one has even more whitespace"
}
}
}
}
}
},
"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
103 changes: 103 additions & 0 deletions tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,109 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/whitespace": {
"post": {
"operationId": "settings-whitespace",
"summary": "some whitespace",
"description": "even more whitespace\nThis endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "integer",
"format": "int64",
"description": "and this one has even more whitespace"
}
}
}
}
}
},
"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 e8584a4

Please sign in to comment.