mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #13097 from appwrite/fix/path-parameters-are-required
fix(sdk): emit path parameters as required
This commit is contained in:
2 files changed
+49
No files matched your search
@@ -832,6 +832,13 @@ class OpenAPI3 extends Format
|
||||
|
||||
if ($parameterNode['path']) { // Param is in URL path (directly or through alias)
|
||||
$node['in'] = 'path';
|
||||
// A route only matches when every path segment is present, so a
|
||||
// path parameter is always supplied whatever the PHP param says.
|
||||
// OpenAPI requires `required: true` here, and generators emit a
|
||||
// bare identifier for the path substitution — an optional one
|
||||
// becomes an undefined reference (Go) or interpolates the
|
||||
// absent value into the URL (Python).
|
||||
$node['required'] = true;
|
||||
$methodTemp['parameters'][] = $node;
|
||||
} elseif (\in_array($method, ['GET', 'DELETE'], true)) { // Param is in query
|
||||
$node['in'] = 'query';
|
||||
|
||||
@@ -321,6 +321,48 @@ final class FormatTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A route only matches when every path segment is present, so a path
|
||||
* parameter is always supplied no matter what the PHP param declares.
|
||||
* Marking one optional produced a Go SDK that does not compile
|
||||
* (`undefined: SessionId`) and a Python SDK that requested
|
||||
* `/account/sessions/None`.
|
||||
*/
|
||||
public function testOptionalPathParameterIsEmittedAsRequired(): void
|
||||
{
|
||||
Method::$processed = [];
|
||||
Method::$errors = [];
|
||||
|
||||
$route = (new Route('GET', '/v1/tests/:sessionId'))
|
||||
->desc('Get test')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'test',
|
||||
group: null,
|
||||
name: 'getPathTest',
|
||||
description: 'Get test.',
|
||||
auth: [],
|
||||
responses: [
|
||||
new SDKResponse(code: 200, model: Response::MODEL_NONE),
|
||||
],
|
||||
))
|
||||
->param('sessionId', 'current', new Text(256), 'Session ID.', true)
|
||||
->param('filter', '', new Text(256), 'Optional query filter.', true);
|
||||
|
||||
$openApi = (new OpenAPI3(new Container(), [], [$route], [new NoneModel()], [], 0, 'console'))->parse();
|
||||
|
||||
$parameters = [];
|
||||
foreach ($openApi['paths']['/tests/{sessionId}']['get']['parameters'] as $parameter) {
|
||||
$parameters[$parameter['name']] = $parameter;
|
||||
}
|
||||
|
||||
$this->assertSame('path', $parameters['sessionId']['in']);
|
||||
$this->assertTrue($parameters['sessionId']['required']);
|
||||
|
||||
// An optional query parameter is untouched — only the path is forced.
|
||||
$this->assertSame('query', $parameters['filter']['in']);
|
||||
$this->assertFalse($parameters['filter']['required']);
|
||||
}
|
||||
|
||||
/**
|
||||
* The project usage handler writes the text embedding metrics as four
|
||||
* per-period lists plus four scalar totals. A typed SDK generated from a
|
||||
|
||||
Reference in new issue
Block a user