Skip to content

Commit

Permalink
Fix: Add support for handling multiple schemas from a comma-separated…
Browse files Browse the repository at this point in the history
… list in schema-loader-utils

- Updated `readSchemas` in `schema-loader-utils.ts` to correctly parse and handle multiple schema files passed as a comma-separated list.
- Added a test case to validate functionality for multiple schemas in `schema-loader-utils.test.ts`.

Addresses issue #2087.
[Bug] Fix issue #2087: Handle multiple schema files in gen-schema-views script
  • Loading branch information
Gustolandia committed Dec 3, 2024
1 parent 8266204 commit 718163a
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 79 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@ describe("filesystem schema loading", () => {
const schemas = schema_loader_utils.readSchemas([globPattern]);
expect(Object.keys(schemas)).to.have.members(results);
});
it("should load schemas from a comma-separated list of file paths", () => {
const schemaFiles = `${schemaDir}/full-directory/schema-1.json,${schemaDir}/full-directory/schema-2.json`;
const schemas = Object.keys(schema_loader_utils.readSchemas([schemaFiles]));
expect(schemas.length).to.equal(2);
expect(schemas).to.include(
schema_loader_utils.filePathToSchemaName(
`${schemaDir}/full-directory/schema-1.json`
)
);
expect(schemas).to.include(
schema_loader_utils.filePathToSchemaName(
`${schemaDir}/full-directory/schema-2.json`
)
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async function parseConfig(): Promise<CliConfig> {
program.outputHelp();
process.exit(1);
}

return {
projectId: program.project,
bigQueryProjectId: program.bigQueryProject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ function resolveFilePath(filePath: string): string {

function expandGlobs(globs: string[]): string[] {
let results = [];
for (var i = 0; i < globs.length; i++) {
const globResults = glob.sync(globs[i]);
// Split any comma-separated globs into individual paths
const expandedGlobs = globs.flatMap((g) => g.split(",").map((s) => s.trim()));
for (const globPath of expandedGlobs) {
const globResults = glob.sync(globPath);
results = results.concat(globResults);
}
return results;
Expand Down
Loading

0 comments on commit 718163a

Please sign in to comment.