@c8y/api-doc 1023.48.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.
@@ -0,0 +1,94 @@
1
+ import { AsyncPipe } from '@angular/common';
2
+ import {
3
+ AfterViewInit,
4
+ Component,
5
+ ElementRef,
6
+ inject,
7
+ OnDestroy,
8
+ ViewChild,
9
+ ViewEncapsulation
10
+ } from '@angular/core';
11
+ import { ActivatedRoute } from '@angular/router';
12
+ import { FetchClient } from '@c8y/client';
13
+ import {
14
+ ActionBarItemComponent,
15
+ C8yTranslatePipe,
16
+ IconDirective,
17
+ TitleComponent,
18
+ UserPreferencesService
19
+ } from '@c8y/ngx-components';
20
+ import { firstValueFrom, map, shareReplay, Subject, switchMap, takeUntil } from 'rxjs';
21
+ import SwaggerUI from 'swagger-ui-dist/swagger-ui-es-bundle';
22
+ import { ApiDocService } from '../api-doc.service';
23
+
24
+ @Component({
25
+ selector: 'api-swagger',
26
+ templateUrl: './swagger.component.html',
27
+ styleUrls: ['./swagger.component.less'],
28
+ encapsulation: ViewEncapsulation.None,
29
+ imports: [IconDirective, ActionBarItemComponent, C8yTranslatePipe, TitleComponent, AsyncPipe]
30
+ })
31
+ export class SwaggerComponent implements OnDestroy, AfterViewInit {
32
+ @ViewChild('apiDocElement', { static: true }) apiDocElement: ElementRef | undefined;
33
+ private fetchClient = inject(FetchClient);
34
+ private activatedRoute = inject(ActivatedRoute);
35
+ private apiDocService = inject(ApiDocService);
36
+ private destroy$ = new Subject<void>();
37
+ private userPreferences = inject(UserPreferencesService);
38
+
39
+ shouldHideAlert$ = this.userPreferences.observe<boolean>('apiDocHideAuthAlert');
40
+ spec$ = this.activatedRoute.paramMap.pipe(
41
+ map(params => params.get('id')),
42
+ switchMap(id => this.apiDocService.getApiDocById(id)),
43
+ switchMap(app => {
44
+ const specPath = app.downloadPath;
45
+ const isYaml = specPath.endsWith('.yaml') || specPath.endsWith('.yml');
46
+ return this.fetchClient
47
+ .fetch(app.downloadPath)
48
+ .then(response => (isYaml ? response.text() : response.json()))
49
+ .then(data => ({ app, data, isYaml }));
50
+ }),
51
+ shareReplay(1)
52
+ );
53
+
54
+ hideAlert() {
55
+ this.userPreferences.set('apiDocHideAuthAlert', true);
56
+ }
57
+
58
+ async downloadSpecFile() {
59
+ const { app, data, isYaml } = await firstValueFrom(this.spec$);
60
+ const content = isYaml ? data : JSON.stringify(data, null, 2);
61
+ const mimeType = isYaml ? 'application/x-yaml' : 'application/json';
62
+ const extension = isYaml ? 'yaml' : 'json';
63
+ const blob = new Blob([content], { type: mimeType });
64
+ const url = window.URL.createObjectURL(blob);
65
+ const link = document.createElement('a');
66
+ link.href = url;
67
+ link.download = `${app.name}-openapi-spec.${extension}`;
68
+ link.click();
69
+ window.URL.revokeObjectURL(url);
70
+ }
71
+
72
+ async ngAfterViewInit() {
73
+ this.spec$.pipe(takeUntil(this.destroy$)).subscribe(({ app, data, isYaml }) => {
74
+ SwaggerUI({
75
+ ...(isYaml ? { url: app.downloadPath } : { spec: data }),
76
+ domNode: this.apiDocElement?.nativeElement,
77
+ requestInterceptor: (req: RequestInit) => {
78
+ if (!req.headers) {
79
+ req.headers = {};
80
+ }
81
+
82
+ const fetchOptions = this.fetchClient.getFetchOptions();
83
+ Object.assign(req.headers, fetchOptions?.headers || {});
84
+ return req;
85
+ }
86
+ });
87
+ });
88
+ }
89
+
90
+ ngOnDestroy(): void {
91
+ this.destroy$.next();
92
+ this.destroy$.complete();
93
+ }
94
+ }
@@ -0,0 +1,18 @@
1
+ import './polyfills';
2
+ import '@angular/compiler';
3
+
4
+ import { enableProdMode } from '@angular/core';
5
+ import { bootstrapApplication } from '@angular/platform-browser';
6
+ import { BootstrapComponent, provideBootstrapMetadata } from '@c8y/ngx-components';
7
+ import { BootstrapMetaData } from '@c8y/bootstrap';
8
+ import { appConfig } from './app/app.config';
9
+
10
+ declare const __MODE__: string;
11
+ if (__MODE__ === 'production') {
12
+ enableProdMode();
13
+ }
14
+
15
+ export function bootstrap(metadata: BootstrapMetaData) {
16
+ appConfig.providers.push(...provideBootstrapMetadata(metadata));
17
+ return bootstrapApplication(BootstrapComponent, appConfig).catch(err => console.log(err));
18
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Internationalizing files in po format (https://en.wikipedia.org/wiki/Gettext#Translating)
3
+ * You can always add additional strings by adding your own po file. All po files are
4
+ * combined to one JSON file per language and are loaded if the specific language is needed.
5
+ */
6
+ import '@c8y/ngx-components/locales/de.po';
7
+ import '@c8y/ngx-components/locales/en.po';
8
+ import '@c8y/ngx-components/locales/en_US.po';
9
+ import '@c8y/ngx-components/locales/es.po';
10
+ import '@c8y/ngx-components/locales/fr.po';
11
+ import '@c8y/ngx-components/locales/ja_JP.po';
12
+ import '@c8y/ngx-components/locales/ko.po';
13
+ import '@c8y/ngx-components/locales/nl.po';
14
+ import '@c8y/ngx-components/locales/pl.po';
15
+ import '@c8y/ngx-components/locales/pt_BR.po';
16
+ import '@c8y/ngx-components/locales/zh_CN.po';
17
+ import '@c8y/ngx-components/locales/zh_TW.po';
18
+ // import './locales/de.po'; // <- adding additional strings to the german translation.
package/src/main.ts ADDED
@@ -0,0 +1,17 @@
1
+ import './i18n';
2
+
3
+ const barHolder: HTMLElement | null = document.querySelector('body > .init-load');
4
+ export const removeProgress = () => barHolder?.parentNode?.removeChild(barHolder);
5
+
6
+ applicationSetup();
7
+
8
+ async function applicationSetup() {
9
+ const { loadMetaDataAndPerformBootstrap } = await import('@c8y/bootstrap');
10
+ const loadBootstrapModule = () =>
11
+ import(
12
+ /* webpackPreload: true */
13
+ './bootstrap'
14
+ );
15
+
16
+ loadMetaDataAndPerformBootstrap(loadBootstrapModule).then(removeProgress);
17
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * This file includes polyfills needed by Angular and is loaded before the app.
3
+ * You can add your own extra polyfills to this file.
4
+ *
5
+ * This file is divided into 2 sections:
6
+ * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7
+ * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8
+ * file.
9
+ *
10
+ * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11
+ * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12
+ * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13
+ *
14
+ * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15
+ */
16
+
17
+ /***************************************************************************************************
18
+ * BROWSER POLYFILLS
19
+ */
20
+
21
+ /**
22
+ * By default, zone.js will patch all possible macroTask and DomEvents
23
+ * user can disable parts of macroTask/DomEvents patch by setting following flags
24
+ */
25
+
26
+ (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
27
+ // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
28
+ (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove', 'message'];
29
+
30
+ /***************************************************************************************************
31
+ * Zone JS is required by default for Angular itself.
32
+ */
33
+ import 'zone.js'; // Included with Angular CLI.
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out-tsc/app",
5
+ "noImplicitOverride": false,
6
+ "skipLibCheck": true,
7
+ "strict": false
8
+ },
9
+ "files": [
10
+ "src/main.ts"
11
+ ],
12
+ "include": [
13
+ "src/**/*.ts",
14
+ "../ngx-components/**/*.ts"
15
+ ],
16
+ "exclude": [
17
+ "../ngx-components/dist",
18
+ "../ngx-components/**/*.spec.ts",
19
+ ]
20
+ }