@@ -55,6 +55,7 @@ import { BASE_URL } from 'src/app/shared/constants/urls';
5555import { Subscription , of , forkJoin } from 'rxjs' ;
5656import { DfApiQuickstartComponent } from '../df-api-quickstart/df-api-quickstart.component' ;
5757import { ApiDocJson } from 'src/app/shared/types/files' ;
58+ import { healthCheckEndpointsInfo } from '../constants/health-check-endpoints' ;
5859import { MatSlideToggleModule } from '@angular/material/slide-toggle' ;
5960import { FormsModule } from '@angular/forms' ;
6061
@@ -84,6 +85,7 @@ interface HealthCheckResult {
8485 MatSelectModule ,
8586 MatIconModule ,
8687 TranslocoModule ,
88+ FormsModule ,
8789 AsyncPipe ,
8890 NgIf ,
8991 NgFor ,
@@ -119,32 +121,6 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
119121 healthError : string | null = null ;
120122 serviceName : string | null = null ;
121123 showUnhealthyErrorDetails = false ;
122- // Mapping of service types to their corresponding endpoints, probably would be better to move to the back-end
123- healthCheckEndpointsInfo : {
124- [ key : string ] : { endpoint : string ; title : string ; description : string } [ ] ;
125- } = {
126- Database : [
127- {
128- endpoint : '/_schema' ,
129- title : 'View Available Schemas' ,
130- description :
131- 'This command fetches a list of schemas from your connected database' ,
132- } ,
133- {
134- endpoint : '/_table' ,
135- title : 'View Tables in Your Database' ,
136- description : 'This command lists all tables in your database' ,
137- } ,
138- ] ,
139- File : [
140- {
141- endpoint : '/' ,
142- title : 'View Available Folders' ,
143- description :
144- 'This command fetches a list of folders from your connected file storage' ,
145- } ,
146- ] ,
147- } ;
148124
149125 private rawHttp : HttpClient ;
150126
@@ -216,51 +192,8 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
216192 }
217193
218194 ngAfterContentInit ( ) : void {
219- const apiDocumentation = this . apiDocJson ;
220195 this . checkApiHealth ( ) ;
221-
222- SwaggerUI ( {
223- spec : apiDocumentation ,
224- domNode : this . apiDocElement ?. nativeElement ,
225- requestInterceptor : ( req : SwaggerUI . Request ) => {
226- req [ 'headers' ] [ SESSION_TOKEN_HEADER ] = this . userDataService . token ;
227- req [ 'headers' ] [ API_KEY_HEADER ] = environment . dfApiDocsApiKey ;
228- // Parse the request URL
229- const url = new URL ( req [ 'url' ] ) ;
230- const params = new URLSearchParams ( url . search ) ;
231- // Decode all parameters
232- params . forEach ( ( value , key ) => {
233- params . set ( key , decodeURIComponent ( value ) ) ;
234- } ) ;
235- // Update the URL with decoded parameters
236- url . search = params . toString ( ) ;
237- req [ 'url' ] = url . toString ( ) ;
238- return req ;
239- } ,
240- showMutatedRequest : true ,
241- onComplete : ( ) => {
242- if (
243- this . apiDocElement &&
244- this . apiDocElement . nativeElement &&
245- this . swaggerInjectedContentContainerRef &&
246- this . swaggerInjectedContentContainerRef . nativeElement
247- ) {
248- const swaggerContainer = this . apiDocElement . nativeElement ;
249- const customContentNode =
250- this . swaggerInjectedContentContainerRef . nativeElement ;
251-
252- const infoContainer = swaggerContainer . querySelector (
253- '.information-container .main'
254- ) ;
255-
256- this . injectCustomContent (
257- swaggerContainer ,
258- infoContainer ,
259- customContentNode
260- ) ;
261- }
262- } ,
263- } ) ;
196+ this . generateSwaggerWithApiKey ( this . apiDocJson ) ;
264197 }
265198
266199 ngOnDestroy ( ) : void {
@@ -270,7 +203,7 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
270203
271204 private checkApiHealth ( ) : void {
272205 let endpointsInfoToValidate =
273- this . healthCheckEndpointsInfo [ this . apiDocJson . info . group ] ;
206+ healthCheckEndpointsInfo [ this . apiDocJson . info . group ] ;
274207 if ( this . serviceName && endpointsInfoToValidate ) {
275208 // Perform health check
276209 this . performHealthCheck ( endpointsInfoToValidate [ 0 ] . endpoint ) ;
@@ -337,6 +270,51 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
337270 this . showUnhealthyErrorDetails = ! this . showUnhealthyErrorDetails ;
338271 }
339272
273+ private generateSwaggerWithApiKey ( apiDocumentation : ApiDocJson ) : void {
274+ SwaggerUI ( {
275+ spec : apiDocumentation ,
276+ domNode : this . apiDocElement ?. nativeElement ,
277+ requestInterceptor : ( req : SwaggerUI . Request ) => {
278+ req [ 'headers' ] [ SESSION_TOKEN_HEADER ] = this . userDataService . token ;
279+ req [ 'headers' ] [ API_KEY_HEADER ] = environment . dfApiDocsApiKey ;
280+ // Parse the request URL
281+ const url = new URL ( req [ 'url' ] ) ;
282+ const params = new URLSearchParams ( url . search ) ;
283+ // Decode all parameters
284+ params . forEach ( ( value , key ) => {
285+ params . set ( key , decodeURIComponent ( value ) ) ;
286+ } ) ;
287+ // Update the URL with decoded parameters
288+ url . search = params . toString ( ) ;
289+ req [ 'url' ] = url . toString ( ) ;
290+ return req ;
291+ } ,
292+ showMutatedRequest : true ,
293+ onComplete : ( ) => {
294+ if (
295+ this . apiDocElement &&
296+ this . apiDocElement . nativeElement &&
297+ this . swaggerInjectedContentContainerRef &&
298+ this . swaggerInjectedContentContainerRef . nativeElement
299+ ) {
300+ const swaggerContainer = this . apiDocElement . nativeElement ;
301+ const customContentNode =
302+ this . swaggerInjectedContentContainerRef . nativeElement ;
303+
304+ const infoContainer = swaggerContainer . querySelector (
305+ '.information-container .main'
306+ ) ;
307+
308+ this . injectCustomContent (
309+ swaggerContainer ,
310+ infoContainer ,
311+ customContentNode
312+ ) ;
313+ }
314+ } ,
315+ } ) ;
316+ }
317+
340318 reloadApiDocs ( ) {
341319 if ( ! this . serviceName ) return ;
342320 const params = this . expandSchema ? '?expand_schema=true' : '' ;
0 commit comments