@c8y/api-doc 1023.68.6 → 1023.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/package.json +7 -7
- package/src/app/api-doc.service.ts +67 -17
package/README.md
CHANGED
|
@@ -13,3 +13,20 @@ It offers it's OpenAPI spec under the relative path `api-json` (`/service/ai/api
|
|
|
13
13
|
|
|
14
14
|
So the `openApiSpec` has to be set to `api-json`.
|
|
15
15
|
|
|
16
|
+
In case you want to expose more than a single OpenAPI spec within a single microservice, you can also provide an array for `openApiSpec`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"openApiSpec": [
|
|
21
|
+
{
|
|
22
|
+
"label": "AI Agents",
|
|
23
|
+
"path": "api-json"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"label": "AI Agents2",
|
|
27
|
+
"path": "api-json2"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c8y/api-doc",
|
|
3
|
-
"version": "1023.
|
|
3
|
+
"version": "1023.70.0",
|
|
4
4
|
"description": "This package is a blueprint application which allows to show all API documentations of the platform.",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@c8y/style": "1023.
|
|
7
|
-
"@c8y/ngx-components": "1023.
|
|
8
|
-
"@c8y/client": "1023.
|
|
9
|
-
"@c8y/bootstrap": "1023.
|
|
6
|
+
"@c8y/style": "1023.70.0",
|
|
7
|
+
"@c8y/ngx-components": "1023.70.0",
|
|
8
|
+
"@c8y/client": "1023.70.0",
|
|
9
|
+
"@c8y/bootstrap": "1023.70.0",
|
|
10
10
|
"@angular/cdk": "^20.2.14",
|
|
11
11
|
"monaco-editor": "~0.53.0",
|
|
12
12
|
"ngx-bootstrap": "20.0.2",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"enabled": false
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@c8y/options": "1023.
|
|
22
|
-
"@c8y/devkit": "1023.
|
|
21
|
+
"@c8y/options": "1023.70.0",
|
|
22
|
+
"@c8y/devkit": "1023.70.0",
|
|
23
23
|
"@types/lodash": "4.17.20"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { inject, Injectable } from '@angular/core';
|
|
2
2
|
import { ApplicationService } from '@c8y/client';
|
|
3
3
|
import { AppStateService, HumanizeAppNamePipe } from '@c8y/ngx-components';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
combineLatest,
|
|
6
|
+
distinctUntilChanged,
|
|
7
|
+
filter,
|
|
8
|
+
from,
|
|
9
|
+
map,
|
|
10
|
+
Observable,
|
|
11
|
+
of,
|
|
12
|
+
shareReplay,
|
|
13
|
+
switchMap,
|
|
14
|
+
take
|
|
15
|
+
} from 'rxjs';
|
|
5
16
|
import { ApiDocApp } from './api-doc-app.model';
|
|
6
17
|
import { sortBy } from 'lodash';
|
|
7
18
|
import { gettext } from '@c8y/ngx-components/gettext';
|
|
@@ -36,11 +47,24 @@ export class ApiDocService {
|
|
|
36
47
|
*/
|
|
37
48
|
getApiDocApps(): Observable<ApiDocApp[]> {
|
|
38
49
|
if (!this.cache$) {
|
|
50
|
+
const appsOfCurrentUser$ = this.appStateService.currentUser.pipe(
|
|
51
|
+
map(user => user?.id),
|
|
52
|
+
distinctUntilChanged(),
|
|
53
|
+
filter(userId => !!userId),
|
|
54
|
+
switchMap(userId =>
|
|
55
|
+
from(
|
|
56
|
+
this.appService.listByUser(userId, {
|
|
57
|
+
pageSize: 2000
|
|
58
|
+
})
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
);
|
|
39
62
|
this.cache$ = combineLatest([
|
|
40
|
-
|
|
41
|
-
this.appStateService.currentApplication
|
|
63
|
+
appsOfCurrentUser$,
|
|
64
|
+
this.appStateService.currentApplication,
|
|
65
|
+
this.appStateService.currentTenant
|
|
42
66
|
]).pipe(
|
|
43
|
-
map(([apps, currentApp]) => {
|
|
67
|
+
map(([apps, currentApp, currentTenant]) => {
|
|
44
68
|
// Update coreApiDocApps with current app's contextPath
|
|
45
69
|
const coreApiDoc: ApiDocApp = {
|
|
46
70
|
...this.CORE_API_DOCS_APP,
|
|
@@ -53,25 +77,51 @@ export class ApiDocService {
|
|
|
53
77
|
);
|
|
54
78
|
return {
|
|
55
79
|
appsWithOpenApiSpec: sortBy(appsWithOpenApiSpec, app => app.name?.toLowerCase() || ''),
|
|
56
|
-
coreApiDoc
|
|
80
|
+
coreApiDoc,
|
|
81
|
+
currentTenant
|
|
57
82
|
};
|
|
58
83
|
}),
|
|
59
|
-
switchMap(({ appsWithOpenApiSpec, coreApiDoc }) => {
|
|
84
|
+
switchMap(({ appsWithOpenApiSpec, coreApiDoc, currentTenant }) => {
|
|
60
85
|
if (appsWithOpenApiSpec.length === 0) {
|
|
61
86
|
return of([coreApiDoc] as ApiDocApp[]);
|
|
62
87
|
}
|
|
63
|
-
const appObservables =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
const appObservables: Observable<ApiDocApp>[] = [];
|
|
89
|
+
for (const app of appsWithOpenApiSpec) {
|
|
90
|
+
if (!app.name || !app.manifest) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const isSubscribedApp = currentTenant?.applications?.references?.some(
|
|
95
|
+
ref => ref.application.id === app.id
|
|
96
|
+
);
|
|
97
|
+
if (!isSubscribedApp) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const openApiSpecSettings: string | { label: string; path: string }[] =
|
|
101
|
+
app.manifest['openApiSpec'];
|
|
102
|
+
|
|
103
|
+
const entriesForApp: { label: string; path: string }[] =
|
|
104
|
+
typeof openApiSpecSettings === 'string'
|
|
105
|
+
? [{ label: app.name, path: openApiSpecSettings }]
|
|
106
|
+
: openApiSpecSettings;
|
|
107
|
+
|
|
108
|
+
appObservables.push(
|
|
109
|
+
...entriesForApp.map(entry =>
|
|
110
|
+
this.humanize.transform(entry.label).pipe(
|
|
111
|
+
map(
|
|
112
|
+
humanizedName =>
|
|
113
|
+
({
|
|
114
|
+
...app,
|
|
115
|
+
id: `${app.id}-${entry.path}`,
|
|
116
|
+
appLabel: humanizedName,
|
|
117
|
+
downloadPath: `/service/${app.contextPath}/${entry.path}`
|
|
118
|
+
}) as ApiDocApp
|
|
119
|
+
)
|
|
120
|
+
)
|
|
72
121
|
)
|
|
73
|
-
)
|
|
74
|
-
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
75
125
|
return combineLatest(appObservables).pipe(map(apiDocApps => [coreApiDoc, ...apiDocApps]));
|
|
76
126
|
}),
|
|
77
127
|
shareReplay(1)
|