mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Fix Response Models
This commit is contained in:
1 parent
a1c70a6956
commit
8f2cca5b0f
6 files changed
+154
-20
No files matched your search
@@ -188,13 +188,6 @@ App::post('/v1/users')
|
||||
->label('scope', 'users.write')
|
||||
->label('audits.event', 'user.create')
|
||||
->label('audits.resource', 'user/{response.$id}')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'users')
|
||||
->label('sdk.method', 'create')
|
||||
->label('sdk.description', '/docs/references/users/create-user.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_USER)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'users',
|
||||
name: 'create',
|
||||
|
||||
@@ -10,6 +10,10 @@ use Appwrite\Event\Func;
|
||||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\SDK\ResponseType;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Request\Filters\V16 as RequestV16;
|
||||
use Appwrite\Utopia\Request\Filters\V17 as RequestV17;
|
||||
@@ -93,8 +97,29 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
$type = $route->getAttribute('resourceType');
|
||||
|
||||
if ($type === 'function') {
|
||||
$utopia->getRoute()?->label('sdk.namespace', 'functions');
|
||||
$utopia->getRoute()?->label('sdk.method', 'createExecution');
|
||||
$method = $utopia->getRoute()?->getLabel('sdk', null);
|
||||
|
||||
if (empty($method)) {
|
||||
$utopia->getRoute()?->label('sdk', new Method(
|
||||
namespace: 'functions',
|
||||
name: 'createExecution',
|
||||
description: '/docs/references/functions/create-execution.md',
|
||||
auth: [AuthType::SESSION, AuthType::KEY, AuthType::JWT],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
model: Response::MODEL_EXECUTION,
|
||||
)
|
||||
],
|
||||
responseType: ResponseType::MULTIPART,
|
||||
requestType: 'application/json',
|
||||
));
|
||||
} else {
|
||||
/** @var Method $method */
|
||||
$method->setNamespace('functions');
|
||||
$method->setMethodName('createExecution');
|
||||
$utopia->getRoute()?->label('sdk', $method);
|
||||
}
|
||||
|
||||
if (System::getEnv('_APP_OPTIONS_FUNCTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS
|
||||
if ($request->getProtocol() !== 'https') {
|
||||
|
||||
@@ -85,13 +85,19 @@ App::post('/v1/account/create')
|
||||
|
||||
```php
|
||||
App::post('/v1/account/jwt')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_SESSION])
|
||||
->label('sdk.namespace', 'account')
|
||||
->label('sdk.method', 'createJWT')
|
||||
->label('sdk.description', '/docs/references/account/create-jwt.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_JWT)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'account',
|
||||
name: 'createJWT',
|
||||
description: '/docs/references/account/create-jwt.md',
|
||||
auth: [],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
model: Response::MODEL_JWT,
|
||||
)
|
||||
],
|
||||
responseType: ResponseType::JSON,
|
||||
))
|
||||
```
|
||||
|
||||
#### Cache
|
||||
|
||||
@@ -211,6 +211,104 @@ class Method
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
public function setNamespace(string $namespace): self
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMethodName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAuth(array $auth): self
|
||||
{
|
||||
$this->validateAuthTypes($auth);
|
||||
$this->auth = $auth;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array<SDKResponse> $responses
|
||||
*/
|
||||
public function setResponses(array $responses): self
|
||||
{
|
||||
foreach ($responses as $response) {
|
||||
$this->validateResponseModel($response->getModel());
|
||||
$this->validateNoContent($response);
|
||||
}
|
||||
$this->responses = $responses;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setResponseType(ResponseType $responseType): self
|
||||
{
|
||||
$this->responseType = $responseType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMethodType(?MethodType $methodType): self
|
||||
{
|
||||
$this->methodType = $methodType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOfflineKey(?string $offlineKey): self
|
||||
{
|
||||
$this->offlineKey = $offlineKey;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOfflineModel(?string $offlineModel): self
|
||||
{
|
||||
$this->offlineModel = $offlineModel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOfflineResponseKey(?string $offlineResponseKey): self
|
||||
{
|
||||
$this->offlineResponseKey = $offlineResponseKey;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDeprecated(bool $deprecated): self
|
||||
{
|
||||
$this->deprecated = $deprecated;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setHide(bool|array $hide): self
|
||||
{
|
||||
$this->hide = $hide;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPackaging(bool $packaging): self
|
||||
{
|
||||
$this->packaging = $packaging;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRequestType(string $requestType): self
|
||||
{
|
||||
$this->requestType = $requestType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setParameters(array $parameters): self
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Throw any errors that were found during initialization
|
||||
public static function finaliseInitialization(): void
|
||||
{
|
||||
|
||||
@@ -28,8 +28,14 @@ class Request extends UtopiaRequest
|
||||
$parameters = parent::getParams();
|
||||
|
||||
if ($this->hasFilters() && self::hasRoute()) {
|
||||
$method = self::getRoute()->getLabel('sdk.method', 'unknown');
|
||||
$endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . $method;
|
||||
$method = self::getRoute()->getLabel('sdk', null);
|
||||
/** @var \Appwrite\SDK\Method $method */
|
||||
|
||||
if (empty($method)) {
|
||||
$endpointIdentifier = 'unknown.unknown';
|
||||
} else {
|
||||
$endpointIdentifier = $method->getNamespace() . '.' . $method->getMethodName();
|
||||
}
|
||||
|
||||
foreach ($this->getFilters() as $filter) {
|
||||
$parameters = $filter->parse($parameters, $endpointIdentifier);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit\Utopia;
|
||||
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\Utopia\Request;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
@@ -31,8 +32,13 @@ class RequestTest extends TestCase
|
||||
$this->assertCount(2, $this->request->getFilters());
|
||||
|
||||
$route = new Route(Request::METHOD_GET, '/test');
|
||||
$route->label('sdk.method', 'method');
|
||||
$route->label('sdk.namespace', 'namespace');
|
||||
$route->label('sdk', new Method(
|
||||
namespace: 'namespace',
|
||||
name: 'method',
|
||||
description: 'description',
|
||||
auth: [],
|
||||
responses: [],
|
||||
));
|
||||
// set test header to prevent header populaten inside the request class
|
||||
$this->request->addHeader('EXAMPLE', 'VALUE');
|
||||
$this->request->setRoute($route);
|
||||
|
||||
Reference in new issue
Block a user