Skip to content

Commit

Permalink
Add header=colId option for the table-schema API gristlabs#719
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent FAYOLLE committed Nov 14, 2023
1 parent 9f521f5 commit 9f7090e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/server/lib/ExportTableSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from 'express';
import {ApiError} from 'app/common/ApiError';
import {ActiveDoc} from 'app/server/lib/ActiveDoc';
import {DownloadOptions, ExportColumn, exportTable} from 'app/server/lib/Export';
import {DownloadOptions, ExportColumn, ExportHeader, exportTable} from 'app/server/lib/Export';

interface FrictionlessFormat {
name: string;
Expand Down Expand Up @@ -51,21 +51,21 @@ export async function collectTableSchemaInFrictionlessFormat(
}

const data = await exportTable(activeDoc, tableRef, req);
const tableSchema = columnsToTableSchema(tableId, data, settings.locale);
const tableSchema = columnsToTableSchema(tableId, data, { locale: settings.locale, header: options.header });
return tableSchema;
}

function columnsToTableSchema(
tableId: string,
{tableName, columns}: {tableName: string, columns: ExportColumn[]},
locale: string,
{ locale, header = "label" }: { locale: string, header?: ExportHeader },
): FrictionlessFormat {
return {
name: tableId.toLowerCase().replace(/_/g, '-'),
title: tableName,
schema: {
fields: columns.map(col => ({
name: col.label,
name: col[ header ],
...(col.description ? {description: col.description} : {}),
...buildTypeField(col, locale),
})),
Expand Down

0 comments on commit 9f7090e

Please sign in to comment.