Skip to content

Commit c646d99

Browse files
authored
Merge pull request #429 from dreamfactorysoftware/DP-713
Adding a way to auto-populate table_name and field_name wildcards using values from DBs
2 parents 2087cc8 + 7e3f14b commit c646d99

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

src/app/adf-api-docs/df-api-docs/df-api-docs.component.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div
22
class="api-doc-button-container"
3-
[class]="(isDarkMode | async) ? 'dark-theme' : ''">
3+
[class]="(isDarkMode | async) ? 'dark-theme' : ''"
4+
style="display: flex; align-items: center; gap: 16px">
45
<button class="cancel-btn" mat-raised-button (click)="goBackToList()">
56
{{ 'goBack' | transloco }}
67
</button>
@@ -80,6 +81,20 @@
8081
*ngIf="serviceName"
8182
[apiDocJson]="apiDocJson"
8283
[serviceName]="serviceName"></df-api-quickstart>
84+
85+
<div
86+
*ngIf="apiDocJson?.info?.group === 'Database'"
87+
style="margin: 16px 0 8px 0">
88+
<mat-slide-toggle
89+
[(ngModel)]="expandSchema"
90+
(ngModelChange)="reloadApiDocs()">
91+
Populate table/field names in API docs
92+
</mat-slide-toggle>
93+
<div style="font-size: 12px; color: #888; margin-left: 40px">
94+
When enabled, the API documentation will include live table and field
95+
names from your database. (May be slow for large databases)
96+
</div>
97+
</div>
8398
</div>
8499

85100
<div #apiDocumentation class="swagger-ui"></div>

src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ import {
4545
distinctUntilChanged,
4646
catchError,
4747
} from 'rxjs/operators';
48-
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
48+
import {
49+
HttpClient,
50+
HttpErrorResponse,
51+
HttpBackend,
52+
HttpHeaders,
53+
} from '@angular/common/http';
4954
import { BASE_URL } from 'src/app/shared/constants/urls';
5055
import { Subscription, of, forkJoin } from 'rxjs';
5156
import { DfApiQuickstartComponent } from '../df-api-quickstart/df-api-quickstart.component';
5257
import { ApiDocJson } from 'src/app/shared/types/files';
58+
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
59+
import { FormsModule } from '@angular/forms';
5360

5461
interface ServiceResponse {
5562
resource: Array<{
@@ -88,6 +95,8 @@ interface HealthCheckResult {
8895
MatExpansionModule,
8996
MatCardModule,
9097
DfApiQuickstartComponent,
98+
MatSlideToggleModule,
99+
FormsModule,
91100
],
92101
})
93102
export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
@@ -103,6 +112,7 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
103112
apiDocJson: ApiDocJson;
104113
apiKeys: ApiKeyInfo[] = [];
105114
faCopy = faCopy;
115+
expandSchema = false;
106116

107117
private subscriptions: Subscription[] = [];
108118
healthStatus: 'loading' | 'healthy' | 'unhealthy' | 'warning' = 'loading';
@@ -136,6 +146,8 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
136146
],
137147
};
138148

149+
private rawHttp: HttpClient;
150+
139151
constructor(
140152
private activatedRoute: ActivatedRoute,
141153
private router: Router,
@@ -145,14 +157,17 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
145157
private clipboard: Clipboard,
146158
private snackBar: MatSnackBar,
147159
private currentServiceService: DfCurrentServiceService,
148-
private http: HttpClient
149-
) {}
160+
private http: HttpClient,
161+
private httpBackend: HttpBackend
162+
) {
163+
this.rawHttp = new HttpClient(httpBackend);
164+
}
150165
isDarkMode = this.themeService.darkMode$;
151166
ngOnInit(): void {
152167
// Get the service name from the route
153168
this.serviceName = this.activatedRoute.snapshot.params['name'];
154169

155-
// First fetch the service ID by name
170+
// First fetch the service ID by name (use normal http)
156171
if (this.serviceName) {
157172
this.subscriptions.push(
158173
this.http
@@ -322,6 +337,25 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit, OnDestroy {
322337
this.showUnhealthyErrorDetails = !this.showUnhealthyErrorDetails;
323338
}
324339

340+
reloadApiDocs() {
341+
if (!this.serviceName) return;
342+
const params = this.expandSchema ? '?expand_schema=true' : '';
343+
const headers = new HttpHeaders({
344+
'X-DreamFactory-API-Key': environment.dfApiDocsApiKey,
345+
'X-DreamFactory-Session-Token': this.userDataService.token || '',
346+
});
347+
this.rawHttp
348+
.get<any>(`${BASE_URL}/api_docs/${this.serviceName}${params}`, {
349+
headers,
350+
})
351+
.subscribe(data => {
352+
if (data) {
353+
this.apiDocJson = data;
354+
}
355+
this.ngAfterContentInit();
356+
});
357+
}
358+
325359
private injectCustomContent(
326360
swaggerContainer: HTMLElement,
327361
infoContainer: HTMLElement | null,

0 commit comments

Comments
 (0)