Skip to content

Commit

Permalink
Merge pull request #159 from Catrobat/create-pull-request/patch-17251…
Browse files Browse the repository at this point in the history
…03132

Bump autogenerated OpenAPI code
  • Loading branch information
dmetzner authored Aug 31, 2024
2 parents b58ef4a + 7e9b0d8 commit ecbef86
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Api/AuthenticationApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function authenticationDelete(
/**
* Operation authenticationGet.
*
* Check token
* Check JWT token validity
*
* @param int &$responseCode The HTTP Response Code
* @param array $responseHeaders Additional HTTP headers to return with the response ()
Expand Down Expand Up @@ -98,7 +98,7 @@ public function authenticationOauthPost(
/**
* Operation authenticationPost.
*
* Login
* Login - create a new JWT token
*
* @param LoginRequest $login_request (required)
* @param int &$responseCode The HTTP Response Code
Expand Down
40 changes: 37 additions & 3 deletions Api/StudioApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,43 @@ interface StudioApiInterface
public function setBearerAuth(?string $value): void;

/**
* Operation studioIdPut.
* Operation studioIdDelete.
*
* Update a Studio
* Delete a studio (only available to studio admins)
*
* @param string $id (required)
* @param string $accept_language (optional, default to 'en')
* @param int &$responseCode The HTTP Response Code
* @param array $responseHeaders Additional HTTP headers to return with the response ()
*/
public function studioIdDelete(
string $id,
string $accept_language,
int &$responseCode,
array &$responseHeaders
): void;

/**
* Operation studioIdGet.
*
* Get studio details (private studios are only available to members)
*
* @param string $id (required)
* @param string $accept_language (optional, default to 'en')
* @param int &$responseCode The HTTP Response Code
* @param array $responseHeaders Additional HTTP headers to return with the response ()
*/
public function studioIdGet(
string $id,
string $accept_language,
int &$responseCode,
array &$responseHeaders
): array|object|null;

/**
* Operation studioIdPost.
*
* Update a Studio (only available to studio admins)
*
* @param string $id (required)
* @param string $accept_language (optional, default to 'en')
Expand All @@ -64,7 +98,7 @@ public function setBearerAuth(?string $value): void;
* @param int &$responseCode The HTTP Response Code
* @param array $responseHeaders Additional HTTP headers to return with the response ()
*/
public function studioIdPut(
public function studioIdPost(
string $id,
string $accept_language,
?string $name,
Expand Down
4 changes: 2 additions & 2 deletions Controller/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function authenticationDeleteAction(Request $request)
/**
* Operation authenticationGet.
*
* Check token
* Check JWT token validity
*
* @param Request $request the Symfony request to handle
*
Expand Down Expand Up @@ -265,7 +265,7 @@ public function authenticationOauthPostAction(Request $request)
/**
* Operation authenticationPost.
*
* Login
* Login - create a new JWT token
*
* @param Request $request the Symfony request to handle
*
Expand Down
176 changes: 172 additions & 4 deletions Controller/StudioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,183 @@
class StudioController extends Controller
{
/**
* Operation studioIdPut.
* Operation studioIdDelete.
*
* Update a Studio
* Delete a studio (only available to studio admins)
*
* @param Request $request the Symfony request to handle
*
* @return Response the Symfony response
*/
public function studioIdPutAction(Request $request, $id)
public function studioIdDeleteAction(Request $request, $id)
{
// Handle authentication
// Authentication 'BearerAuth' required
// HTTP bearer authentication required
$securityBearerAuth = $request->headers->get('authorization');

// Read out all input parameter values into variables
$accept_language = $request->headers->get('Accept-Language', 'en');

// Use the default value if no value was provided

// Deserialize the input values that needs it
try {
$id = $this->deserialize($id, 'string', 'string');
$accept_language = $this->deserialize($accept_language, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}

// Validate the input values
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\Type('string');
$asserts[] = new Assert\Regex('/^[a-zA-Z0-9\\-]+$/');
$response = $this->validate($id, $asserts);
if ($response instanceof Response) {
return $response;
}
$asserts = [];
$asserts[] = new Assert\Type('string');
$response = $this->validate($accept_language, $asserts);
if ($response instanceof Response) {
return $response;
}

try {
$handler = $this->getApiHandler();

// Set authentication method 'BearerAuth'
$handler->setBearerAuth($securityBearerAuth);

// Make the call to the business logic
$responseCode = 204;
$responseHeaders = [];

$handler->studioIdDelete($id, $accept_language, $responseCode, $responseHeaders);

$message = match ($responseCode) {
204 => 'OK',
400 => 'Bad request (Invalid, or missing parameters)',
401 => 'Invalid JWT token | JWT token not found | JWT token expired',
403 => 'Insufficient privileges, action not allowed.',
404 => 'Not found',
406 => 'Not acceptable - client must accept application/json as content type',
default => '',
};

return new Response(
'',
$responseCode,
array_merge(
$responseHeaders,
[
'X-OpenAPI-Message' => $message,
]
)
);
} catch (\Throwable $fallthrough) {
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
}
}

/**
* Operation studioIdGet.
*
* Get studio details (private studios are only available to members)
*
* @param Request $request the Symfony request to handle
*
* @return Response the Symfony response
*/
public function studioIdGetAction(Request $request, $id)
{
// Figure out what data format to return to the client
$produces = ['application/json'];
// Figure out what the client accepts
$clientAccepts = $request->headers->has('Accept') ? $request->headers->get('Accept') : '*/*';
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
if (null === $responseFormat) {
return new Response('', 406);
}

// Handle authentication

// Read out all input parameter values into variables
$accept_language = $request->headers->get('Accept-Language', 'en');

// Use the default value if no value was provided

// Deserialize the input values that needs it
try {
$id = $this->deserialize($id, 'string', 'string');
$accept_language = $this->deserialize($accept_language, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}

// Validate the input values
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\Type('string');
$asserts[] = new Assert\Regex('/^[a-zA-Z0-9\\-]+$/');
$response = $this->validate($id, $asserts);
if ($response instanceof Response) {
return $response;
}
$asserts = [];
$asserts[] = new Assert\Type('string');
$response = $this->validate($accept_language, $asserts);
if ($response instanceof Response) {
return $response;
}

try {
$handler = $this->getApiHandler();

// Make the call to the business logic
$responseCode = 200;
$responseHeaders = [];

$result = $handler->studioIdGet($id, $accept_language, $responseCode, $responseHeaders);

$message = match ($responseCode) {
200 => 'OK',
400 => 'Bad request (Invalid, or missing parameters)',
401 => 'Invalid JWT token | JWT token not found | JWT token expired',
403 => 'Insufficient privileges, action not allowed.',
404 => 'Not found',
406 => 'Not acceptable - client must accept application/json as content type',
default => '',
};

return new Response(
null !== $result ? $this->serialize($result, $responseFormat) : '',
$responseCode,
array_merge(
$responseHeaders,
[
'Content-Type' => $responseFormat,
'X-OpenAPI-Message' => $message,
]
)
);
} catch (\Throwable $fallthrough) {
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
}
}

/**
* Operation studioIdPost.
*
* Update a Studio (only available to studio admins)
*
* @param Request $request the Symfony request to handle
*
* @return Response the Symfony response
*/
public function studioIdPostAction(Request $request, $id)
{
// Figure out what data format to return to the client
$produces = ['application/json'];
Expand Down Expand Up @@ -150,7 +318,7 @@ public function studioIdPutAction(Request $request, $id)
$responseCode = 200;
$responseHeaders = [];

$result = $handler->studioIdPut($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders);
$result = $handler->studioIdPost($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders);

$message = match ($responseCode) {
200 => 'Studio successfully updated.',
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ All URIs are relative to *https://share.catrob.at/api*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AuthenticationApiInterface* | [**authenticationDelete**](docs/Api/AuthenticationApiInterface.md#authenticationdelete) | **DELETE** /authentication | Expires refresh token
*AuthenticationApiInterface* | [**authenticationGet**](docs/Api/AuthenticationApiInterface.md#authenticationget) | **GET** /authentication | Check token
*AuthenticationApiInterface* | [**authenticationGet**](docs/Api/AuthenticationApiInterface.md#authenticationget) | **GET** /authentication | Check JWT token validity
*AuthenticationApiInterface* | [**authenticationOauthPost**](docs/Api/AuthenticationApiInterface.md#authenticationoauthpost) | **POST** /authentication/oauth | OAuth Login
*AuthenticationApiInterface* | [**authenticationPost**](docs/Api/AuthenticationApiInterface.md#authenticationpost) | **POST** /authentication | Login
*AuthenticationApiInterface* | [**authenticationPost**](docs/Api/AuthenticationApiInterface.md#authenticationpost) | **POST** /authentication | Login - create a new JWT token
*AuthenticationApiInterface* | [**authenticationRefreshPost**](docs/Api/AuthenticationApiInterface.md#authenticationrefreshpost) | **POST** /authentication/refresh | Refresh token
*AuthenticationApiInterface* | [**authenticationUpgradePost**](docs/Api/AuthenticationApiInterface.md#authenticationupgradepost) | **POST** /authentication/upgrade | Upgrade a deprecated token to JWT
*MediaLibraryApiInterface* | [**mediaFileIdGet**](docs/Api/MediaLibraryApiInterface.md#mediafileidget) | **GET** /media/file/{id} | Get the information of a specific media file
Expand All @@ -141,7 +141,9 @@ Class | Method | HTTP request | Description
*ProjectsApiInterface* | [**projectsUserGet**](docs/Api/ProjectsApiInterface.md#projectsuserget) | **GET** /projects/user | Get the projects of the logged in user
*ProjectsApiInterface* | [**projectsUserIdGet**](docs/Api/ProjectsApiInterface.md#projectsuseridget) | **GET** /projects/user/{id} | Get the public projects of a given user
*SearchApiInterface* | [**searchGet**](docs/Api/SearchApiInterface.md#searchget) | **GET** /search | Search for projects, users,..
*StudioApiInterface* | [**studioIdPut**](docs/Api/StudioApiInterface.md#studioidput) | **PUT** /studio/{id} | Update a Studio
*StudioApiInterface* | [**studioIdDelete**](docs/Api/StudioApiInterface.md#studioiddelete) | **DELETE** /studio/{id} | Delete a studio (only available to studio admins)
*StudioApiInterface* | [**studioIdGet**](docs/Api/StudioApiInterface.md#studioidget) | **GET** /studio/{id} | Get studio details (private studios are only available to members)
*StudioApiInterface* | [**studioIdPost**](docs/Api/StudioApiInterface.md#studioidpost) | **POST** /studio/{id} | Update a Studio (only available to studio admins)
*StudioApiInterface* | [**studioPost**](docs/Api/StudioApiInterface.md#studiopost) | **POST** /studio | Create a new Studio
*UserApiInterface* | [**userDelete**](docs/Api/UserApiInterface.md#userdelete) | **DELETE** /user | Delete user account
*UserApiInterface* | [**userGet**](docs/Api/UserApiInterface.md#userget) | **GET** /user | Get your private user data
Expand Down
22 changes: 19 additions & 3 deletions Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,27 @@ open_api_server_search_searchget:
_controller: open_api_server.controller.search::searchGetAction

# studio
open_api_server_studio_studioidput:
open_api_server_studio_studioiddelete:
path: /studio/{id}
methods: [PUT]
methods: [DELETE]
defaults:
_controller: open_api_server.controller.studio::studioIdDeleteAction
requirements:
id: '^[a-zA-Z0-9\\-]+$'

open_api_server_studio_studioidget:
path: /studio/{id}
methods: [GET]
defaults:
_controller: open_api_server.controller.studio::studioIdGetAction
requirements:
id: '^[a-zA-Z0-9\\-]+$'

open_api_server_studio_studioidpost:
path: /studio/{id}
methods: [POST]
defaults:
_controller: open_api_server.controller.studio::studioIdPutAction
_controller: open_api_server.controller.studio::studioIdPostAction
requirements:
id: '^[a-zA-Z0-9\\-]+$'

Expand Down
4 changes: 2 additions & 2 deletions Tests/Api/AuthenticationApiInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testAuthenticationDelete(): void
/**
* Test case for authenticationGet.
*
* Check token.
* Check JWT token validity.
*/
public function testAuthenticationGet(): void
{
Expand Down Expand Up @@ -128,7 +128,7 @@ public function testAuthenticationOauthPost(): void
/**
* Test case for authenticationPost.
*
* Login.
* Login - create a new JWT token.
*/
public function testAuthenticationPost(): void
{
Expand Down
Loading

0 comments on commit ecbef86

Please sign in to comment.