Skip to content

Commit 32db6d1

Browse files
Merge pull request #1559 from keboola/revert-1558-revert-1553-roman/pat-663-new-component-detail-endpoint
Revert "Revert "Roman/pat 663 new component detail endpoint""
2 parents b82e938 + 6ce886e commit 32db6d1

4 files changed

Lines changed: 149 additions & 25 deletions

File tree

apiary.apib

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7375,13 +7375,84 @@ Use this API call to obtain the definition of component for [Development Branch]
73757375
"uiOptions": {},
73767376
"configurationDescription": "The tree data must be stored in a child-parent relationship. A column named **levels** will be added to the table (root nodes will have number 1). Additionally, a column named **root** will be added, containing the ID of the root item.\n\nSample input \n-------------------\n\ncategoryId | categoryParentId\t| title\n--- | --- | --- \n1 |\t0 | foo\n2 | 1 | bar\n3 | 1 | baz\n4 | 2 | buzz\n\n\nSample output\n-------------------\n\ncategoryId | categoryParentId | title | levels | root\n--- | --- | --- | --- | --- |\n1 |\t0 | foo | 1 | 1 |\n2 | 1 | bar | 2 | 1 |\n3 | 1 | baz | 2 | 1 |\n4 | 2 | buzz | 3 | 1 |",
73777377
"uri": "https://syrup.keboola.com/docker/keboola.app-tree",
7378+
"dataTypesConfiguration": {},
7379+
"processorConfiguration": {}
73787380
}
73797381
7380-
### Get component - without branch in URL (deprecated) [GET]
7382+
### Get component - without branch in URL (without authentification) [GET]
7383+
7384+
**Without authentication**, you can call this endpoint without the `X-StorageApi-Token` and still get the component details.
7385+
7386+
+ Parameters
7387+
+ componentId - Component ID - e.g. `keboola.app-tree`
73817388
7382-
***Deprecated**, use the branch endpoint and set `branch/default`.*
73837389
73847390
+ Response 200
7391+
+ Headers
7392+
7393+
Content-type: application/json
7394+
+ Body
7395+
7396+
{
7397+
"id": "keboola.app-tree",
7398+
"type": "application",
7399+
"name": "Tree depth",
7400+
"description": "Application which computes a tree depth.",
7401+
"longDescription": "This application computes levels in a table representing a tree (e.g. product categories). The tree data must be stored in a child-parent relationship. A column named **levels** will be added to the table (root nodes will have number 1). Additionally, a column named **root** will be added, containing the ID of the root item.",
7402+
"hasUI": false,
7403+
"hasRun": false,
7404+
"ico32": "https://d3iz2gfan5zufq.cloudfront.net/images/cloud-services/keboola.app-tree-32-1.png",
7405+
"ico64": "https://d3iz2gfan5zufq.cloudfront.net/images/cloud-services/keboola.app-tree-64-1.png",
7406+
"ico128": "https://d3iz2gfan5zufq.cloudfront.net/images/cloud-services/keboola.app-tree-128-1.png",
7407+
"data": {
7408+
"definition": {
7409+
"type": "aws-ecr",
7410+
"uri": "147946154733.dkr.ecr.us-east-1.amazonaws.com/keboola/app-tree",
7411+
"tag": "latest",
7412+
"repository": {
7413+
"region": "us-east-1"
7414+
}
7415+
},
7416+
"cpu_shares": 1024,
7417+
"memory": "8024m",
7418+
"configuration_format": "json",
7419+
"process_timeout": 10800
7420+
},
7421+
"flags": [
7422+
"genericDockerUI",
7423+
"genericDockerUI-tableInput",
7424+
"genericDockerUI-tableOutput",
7425+
"excludeFromNewList"
7426+
],
7427+
"configurationSchema": {
7428+
"title": "Parameters",
7429+
"type": "object",
7430+
"properties": {
7431+
"idColumn": {
7432+
"type": "string",
7433+
"title": "ID Column",
7434+
"description": "Name of the column containing row identifier",
7435+
"default": "categoryId"
7436+
},
7437+
"parentColumn": {
7438+
"type": "string",
7439+
"title": "Parent Column",
7440+
"description": "Name of the column containing parent identifier",
7441+
"default": "categoryParentId"
7442+
}
7443+
},
7444+
"required": [
7445+
"idColumn",
7446+
"parentColumn"
7447+
]
7448+
},
7449+
"emptyConfiguration": {},
7450+
"uiOptions": {},
7451+
"configurationDescription": "The tree data must be stored in a child-parent relationship. A column named **levels** will be added to the table (root nodes will have number 1). Additionally, a column named **root** will be added, containing the ID of the root item.\n\nSample input \n-------------------\n\ncategoryId | categoryParentId\t| title\n--- | --- | --- \n1 |\t0 | foo\n2 | 1 | bar\n3 | 1 | baz\n4 | 2 | buzz\n\n\nSample output\n-------------------\n\ncategoryId | categoryParentId | title | levels | root\n--- | --- | --- | --- | --- |\n1 |\t0 | foo | 1 | 1 |\n2 | 1 | bar | 2 | 1 |\n3 | 1 | baz | 2 | 1 |\n4 | 2 | buzz | 3 | 1 |",
7452+
"uri": "https://syrup.keboola.com/docker/keboola.app-tree",
7453+
"dataTypesConfiguration": {},
7454+
"processorConfiguration": {}
7455+
}
73857456
73867457
## Get components [/v2/storage/components]
73877458
### Get components [GET /v2/storage/branch/{branch_id}/components?include={include}&componentType={componentType}&isDeleted={isDeleted}]
@@ -7487,7 +7558,9 @@ KBC Component architecture, see the [Developers documentation](https://developer
74877558
"changeDescription": "Configuration deleted"
74887559
}
74897560
}
7490-
]
7561+
],
7562+
"dataTypesConfiguration": {},
7563+
"processorConfiguration": {}
74917564
}
74927565
]
74937566

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,6 @@ parameters:
990990
count: 1
991991
path: src/Keboola/StorageApi/Components.php
992992

993-
-
994-
message: "#^Method Keboola\\\\StorageApi\\\\Components\\:\\:getComponent\\(\\) has no return type specified\\.$#"
995-
count: 1
996-
path: src/Keboola/StorageApi/Components.php
997-
998993
-
999994
message: "#^Method Keboola\\\\StorageApi\\\\Components\\:\\:getComponent\\(\\) has parameter \\$componentId with no type specified\\.$#"
1000995
count: 1
@@ -1085,11 +1080,6 @@ parameters:
10851080
count: 1
10861081
path: src/Keboola/StorageApi/Components.php
10871082

1088-
-
1089-
message: "#^Method Keboola\\\\StorageApi\\\\Components\\:\\:listComponents\\(\\) has no return type specified\\.$#"
1090-
count: 1
1091-
path: src/Keboola/StorageApi/Components.php
1092-
10931083
-
10941084
message: "#^Method Keboola\\\\StorageApi\\\\Components\\:\\:listConfigurationMetadata\\(\\) has no return type specified\\.$#"
10951085
count: 1

src/Keboola/StorageApi/Components.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
use Keboola\StorageApi\Options\Components\ListConfigurationVersionsOptions;
1515
use Keboola\StorageApi\Options\Components\ListConfigurationWorkspacesOptions;
1616

17+
/**
18+
* @phpstan-type Component array{id: string, type: string, name: string, description: string, longDescription: string, version: int, complexity: string, categories: list<string>, hasUI: bool, hasRun: bool, ico32: string, ico64: string, ico128: string, data: array, flags: list<string>, configurationSchema: array, configurationRowSchema: array, emptyConfiguration: array, emptyConfigurationRow: array, createConfigurationRowSchema: array, uiOptions: array, configurationDescription: string, features: list<string>, expiredOn: string, dataTypesConfiguration: array, processorConfiguration: array, uri: string, documentationUrl: string}
19+
* @phpstan-type ComponentListItem array{id: string, type: string, name: string, description: string, longDescription: string, version: int, complexity: string, categories: list<string>, hasUI: bool, hasRun: bool, ico32: string, ico64: string, ico128: string, data: array, flags: list<string>, configurationSchema: array, configurationRowSchema: array, emptyConfiguration: array, emptyConfigurationRow: array, createConfigurationRowSchema: array, uiOptions: array, configurationDescription: string, features: list<string>, expiredOn: string, dataTypesConfiguration: array, configurations: array, processorConfiguration: array, uri: string, documentationUrl: string}
20+
*/
1721
class Components
1822
{
1923
private string $branchPrefix = '';
@@ -118,17 +122,31 @@ public function resetToDefault($componentId, $configurationId)
118122
return $this->client->apiPostJson($this->branchPrefix . "components/{$componentId}/configs/{$configurationId}/reset-to-default");
119123
}
120124

121-
public function listComponents(?ListComponentsOptions $options = null)
125+
/** @return ComponentListItem[] */
126+
public function listComponents(?ListComponentsOptions $options = null): array
122127
{
123128
if (!$options) {
124129
$options = new ListComponentsOptions();
125130
}
126-
return $this->client->apiGet($this->branchPrefix . 'components?' . http_build_query($options->toParamsArray()));
131+
/** @var ComponentListItem[] $result */
132+
$result = $this->client->apiGet($this->branchPrefix . 'components?' . http_build_query($options->toParamsArray()));
133+
return $result;
127134
}
128135

129-
public function getComponent($componentId)
136+
/** @return Component */
137+
public function getComponent($componentId): array
130138
{
131-
return $this->client->apiGet($this->branchPrefix . "components/{$componentId}");
139+
/** @var Component $result */
140+
$result = $this->client->apiGet($this->branchPrefix . "components/{$componentId}");
141+
return $result;
142+
}
143+
144+
/** @return Component */
145+
public function getPublicComponentDetail(string $componentId): array
146+
{
147+
/** @var Component $result */
148+
$result = $this->client->apiGet('components/'.$componentId);
149+
return $result;
132150
}
133151

134152
public function listComponentConfigurations(ListComponentConfigurationsOptions $options)

tests/Common/ComponentsTest.php

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use Keboola\StorageApi\BranchAwareClient;
55
use Keboola\StorageApi\Client;
66
use Keboola\StorageApi\ClientException;
7-
use Keboola\StorageApi\Event;
87
use Keboola\StorageApi\Options\Components\Configuration;
98
use Keboola\StorageApi\Options\Components\ConfigurationRow;
109
use Keboola\StorageApi\Options\Components\ConfigurationRowState;
@@ -17,10 +16,7 @@
1716
use Keboola\Test\ClientProvider\ClientProvider;
1817
use Keboola\Test\StorageApiTestCase;
1918
use Keboola\Test\Utils\EventsQueryBuilder;
20-
use Symfony\Component\Console\Helper\Table;
21-
use Symfony\Component\Console\Output\BufferedOutput;
2219
use function json_decode;
23-
use function var_dump;
2420

2521
class ComponentsTest extends StorageApiTestCase
2622
{
@@ -44,6 +40,22 @@ public function setUp(): void
4440
$this->client = $this->clientProvider->createClientForCurrentTest();
4541
}
4642

43+
public function testPublicGetComponentDetail(): void
44+
{
45+
$componentId = 'wr-db';
46+
47+
$componentsClient = new \Keboola\StorageApi\Components(new Client(
48+
['url' => $this->client->getApiUrl(), 'token' => ''],
49+
));
50+
$component = $componentsClient->getPublicComponentDetail($componentId);
51+
52+
$this->assertEquals('wr-db', $component['id']);
53+
54+
$this->assertComponentsHasKeys($component);
55+
56+
$this->assertArrayNotHasKey('configurations', $component);
57+
}
58+
4759
public function testDeprecatedUrlWithoutBranchIdStillWorks(): void
4860
{
4961
/** @var array $configuration */
@@ -68,10 +80,7 @@ public function testGetComponentDetail(): void
6880

6981
$this->assertEquals('wr-db', $component['id']);
7082

71-
$this->assertArrayHasKey('name', $component);
72-
$this->assertArrayHasKey('type', $component);
73-
$this->assertArrayHasKey('description', $component);
74-
$this->assertArrayHasKey('uri', $component);
83+
$this->assertComponentsHasKeys($component);
7584

7685
$this->assertArrayNotHasKey('configurations', $component);
7786
}
@@ -137,6 +146,8 @@ public function testListComponents(): void
137146
$component = reset($componentsNoInclude);
138147

139148
$configuration = reset($component['configurations']);
149+
$this->assertComponentsHasKeys($component);
150+
140151
$this->assertArrayNotHasKey('configuration', $configuration);
141152
$this->assertArrayNotHasKey('rows', $configuration);
142153
$this->assertArrayNotHasKey('state', $configuration);
@@ -4072,4 +4083,36 @@ public function testConfigurationStateUpdate(): void
40724083

40734084
$this->assertSame($configuration, $components->getConfiguration($componentId, $configurationId));
40744085
}
4086+
4087+
public function assertComponentsHasKeys(array $component): void
4088+
{
4089+
$this->assertArrayHasKey('id', $component);
4090+
$this->assertArrayHasKey('uri', $component);
4091+
$this->assertArrayHasKey('name', $component);
4092+
$this->assertArrayHasKey('description', $component);
4093+
$this->assertArrayHasKey('version', $component);
4094+
$this->assertArrayHasKey('complexity', $component);
4095+
$this->assertArrayHasKey('categories', $component);
4096+
$this->assertArrayHasKey('hasRun', $component);
4097+
$this->assertArrayHasKey('hasUI', $component);
4098+
$this->assertArrayHasKey('ico32', $component);
4099+
$this->assertArrayHasKey('ico64', $component);
4100+
$this->assertArrayHasKey('ico128', $component);
4101+
$this->assertArrayHasKey('type', $component);
4102+
$this->assertArrayHasKey('data', $component);
4103+
$this->assertArrayHasKey('flags', $component);
4104+
$this->assertArrayHasKey('documentationUrl', $component);
4105+
$this->assertArrayHasKey('longDescription', $component);
4106+
$this->assertArrayHasKey('configurationSchema', $component);
4107+
$this->assertArrayHasKey('configurationRowSchema', $component);
4108+
$this->assertArrayHasKey('emptyConfiguration', $component);
4109+
$this->assertArrayHasKey('emptyConfigurationRow', $component);
4110+
$this->assertArrayHasKey('createConfigurationRowSchema', $component);
4111+
$this->assertArrayHasKey('configurationDescription', $component);
4112+
$this->assertArrayHasKey('uiOptions', $component);
4113+
$this->assertArrayHasKey('features', $component);
4114+
$this->assertArrayHasKey('expiredOn', $component);
4115+
$this->assertArrayHasKey('dataTypesConfiguration', $component);
4116+
$this->assertArrayHasKey('processorConfiguration', $component);
4117+
}
40754118
}

0 commit comments

Comments
 (0)