Skip to content

Commit dd2055a

Browse files
authored
Merge pull request #2075 from nextcloud/fix-export-scheme
fix: Export JSON scheme
2 parents e02e2ab + c5d3668 commit dd2055a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

lib/Controller/Api1Controller.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
3737
use OCP\AppFramework\Http\Attribute\OpenAPI;
3838
use OCP\AppFramework\Http\DataResponse;
39+
use OCP\AppFramework\Http\JSONResponse;
3940
use OCP\IL10N;
4041
use OCP\IRequest;
4142
use Psr\Log\LoggerInterface;
@@ -148,9 +149,9 @@ public function createTable(string $title, ?string $emoji, string $template = 'c
148149
* returns table scheme
149150
*
150151
* @param int $tableId Table ID
151-
* @return DataResponse<Http::STATUS_OK, TablesTable, array{'Content-Disposition'?:string,'Content-Type'?:string}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
152+
* @return JSONResponse<Http::STATUS_OK, TablesTable, array{'Content-Disposition': string, 'Content-Type': string}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
152153
*
153-
* 200: Table returned
154+
* 200: Scheme returned
154155
* 403: No permissions
155156
* 404: Not found
156157
*/
@@ -159,10 +160,19 @@ public function createTable(string $title, ?string $emoji, string $template = 'c
159160
#[CORS]
160161
#[RequirePermission(permission: Application::PERMISSION_READ, type: Application::NODE_TYPE_TABLE, idParam: 'tableId')]
161162
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
162-
public function showScheme(int $tableId): DataResponse {
163+
public function showScheme(int $tableId): JSONResponse|DataResponse {
163164
try {
164165
$scheme = $this->tableService->getScheme($tableId, $this->userId);
165-
return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ['Content-Disposition' => 'attachment; filename="' . $scheme->getTitle() . '.json"', 'Content-Type' => 'application/octet-stream']);
166+
$filename = $scheme->getTitle() . '.json';
167+
168+
return new JSONResponse(
169+
$scheme->jsonSerialize(),
170+
Http::STATUS_OK,
171+
[
172+
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
173+
'Content-Type' => 'application/json',
174+
]
175+
);
166176
} catch (PermissionError $e) {
167177
$this->logger->warning('A permission error occurred: ' . $e->getMessage());
168178
$message = ['message' => $e->getMessage()];

openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@
13721372
],
13731373
"responses": {
13741374
"200": {
1375-
"description": "Table returned",
1375+
"description": "Scheme returned",
13761376
"headers": {
13771377
"Content-Disposition": {
13781378
"schema": {

src/types/openapi/openapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ export interface operations {
13991399
};
14001400
readonly requestBody?: never;
14011401
readonly responses: {
1402-
/** @description Table returned */
1402+
/** @description Scheme returned */
14031403
readonly 200: {
14041404
headers: {
14051405
readonly "Content-Disposition"?: string;

0 commit comments

Comments
 (0)