Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/typegen/src/fmodata/generateODataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function generateTableOccurrence(
existingFields?: ParsedTableOccurrence,
alwaysOverrideFieldNames?: boolean,
importAliases?: Map<string, string>, // Map base name -> alias (e.g., "textField" -> "tf")
includeAllFieldsByDefault?: boolean,
): GeneratedTO {
const fmtId = entityType["@TableID"];
const keyFields = entityType.$Key || [];
Expand Down Expand Up @@ -232,6 +233,12 @@ function generateTableOccurrence(
}
}

// Determine includeAllFieldsByDefault: table-level override takes precedence, then top-level, default to true
const effectiveIncludeAllFieldsByDefault =
tableOverride?.includeAllFieldsByDefault ??
includeAllFieldsByDefault ??
true;

// Generate field builder definitions
const fieldLines: string[] = [];
const fieldEntries = Array.from(fields.entries());
Expand All @@ -250,6 +257,11 @@ function generateTableOccurrence(
continue;
}

// If includeAllFieldsByDefault is false, only include fields explicitly listed
if (!effectiveIncludeAllFieldsByDefault && !fieldOverride) {
continue;
}

validFieldEntries.push(entry);
}

Expand Down Expand Up @@ -933,6 +945,7 @@ export async function generateODataTypes(
clearOldFiles = true,
tables,
alwaysOverrideFieldNames = true,
includeAllFieldsByDefault = true,
} = config;
const outputPath = path ?? "schema";

Expand Down Expand Up @@ -993,6 +1006,7 @@ export async function generateODataTypes(
undefined,
tableAlwaysOverrideFieldNames,
undefined,
includeAllFieldsByDefault,
);
generatedTOs.push({
...generated,
Expand Down Expand Up @@ -1052,6 +1066,7 @@ export async function generateODataTypes(
existingFields,
tableAlwaysOverrideFieldNames,
existingFields.importAliases,
includeAllFieldsByDefault,
)
: generated;

Expand Down
8 changes: 8 additions & 0 deletions packages/typegen/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ const tableConfig = z.object({
description:
"If undefined, the top-level setting will be used. If true, field names will always be updated to match metadata, even when matching by entity ID. If false, existing field names are preserved when matching by entity ID.",
}),
includeAllFieldsByDefault: z.boolean().optional().meta({
description:
"If true, all fields will be included by default. If false, only fields that are explicitly listed in the `fields` array will be included.",
}),
});

const typegenConfigSingleBase = z.discriminatedUnion("type", [
Expand Down Expand Up @@ -182,6 +186,10 @@ const typegenConfigSingleBase = z.discriminatedUnion("type", [
description:
"Required array of tables to generate. Only the tables specified here will be downloaded and generated. Each table can have field-level overrides for excluding fields, renaming variables, and overriding field types.",
}),
includeAllFieldsByDefault: z.boolean().default(true).optional().meta({
description:
"If true, all fields will be included by default. If false, only fields that are explicitly listed in the `fields` array will be included.",
}),
}),
]);

Expand Down
1 change: 1 addition & 0 deletions packages/typegen/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function createFmodataConfig(): SingleConfig {
},
tables: [],
alwaysOverrideFieldNames: true,
includeAllFieldsByDefault: true,
};
}

Expand Down
12 changes: 12 additions & 0 deletions packages/typegen/web/src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ export function ConfigEditor({ index, onRemove }: ConfigEditorProps) {
/>
)}
/>
<FormField
control={control}
name={`config.${index}.includeAllFieldsByDefault` as const}
render={({ field }) => (
<SwitchField
label="Include All Fields By Default"
infoTooltip="If true, all fields from metadata will be included unless explicitly excluded. If false, only fields defined in the fields array will be included."
checked={field.value ?? true}
onCheckedChange={field.onChange}
/>
)}
/>
</div>
)}

Expand Down
Loading
Loading