feat(csv-loader): expand custom type references in schemas
Allow custom type names to be expanded before parsing the schema string. This enables using declared types within complex structures like tuples or arrays. The original schema string is preserved for type generation to ensure the output uses the named type rather than the expanded inline definition.
This commit is contained in:
@@ -209,11 +209,21 @@ export function parseCsv(
|
||||
// Check if schema string matches a declared type name
|
||||
let schema: Schema;
|
||||
let declaredTypeName: string | undefined;
|
||||
let columnSchemaString: string | undefined;
|
||||
if (declaredTypes.has(schemaString)) {
|
||||
schema = declaredTypes.get(schemaString)!;
|
||||
declaredTypeName = schemaString;
|
||||
} else {
|
||||
schema = parseSchema(schemaString);
|
||||
// Expand any custom type name references before parsing
|
||||
const expandedSchema = expandSchemaString(
|
||||
schemaString,
|
||||
declaredSchemaStrings,
|
||||
);
|
||||
schema = parseSchema(expandedSchema.trim());
|
||||
// Only preserve the original schema string if expansion actually changed it
|
||||
if (expandedSchema !== schemaString) {
|
||||
columnSchemaString = schemaString;
|
||||
}
|
||||
}
|
||||
|
||||
const config: PropertyConfig = {
|
||||
@@ -222,6 +232,7 @@ export function parseCsv(
|
||||
validator: createValidator(schema),
|
||||
parser: (valueString: string) => parseValue(schema, valueString),
|
||||
declaredTypeName,
|
||||
schemaString: columnSchemaString,
|
||||
};
|
||||
|
||||
if (schema.type === "reference") {
|
||||
|
||||
Reference in New Issue
Block a user