From cebbf8a27f3c4c0ae34c632dcecd2e354bdb421f Mon Sep 17 00:00:00 2001 From: djamaile Date: Mon, 24 Jul 2023 20:53:02 +0200 Subject: [PATCH] feat(cli): enable to print the config schema non merged Signed-off-by: djamaile --- .changeset/rare-pens-exist.md | 5 +++++ packages/cli/src/commands/config/schema.ts | 26 +++++++++++++--------- packages/cli/src/commands/index.ts | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .changeset/rare-pens-exist.md diff --git a/.changeset/rare-pens-exist.md b/.changeset/rare-pens-exist.md new file mode 100644 index 0000000000..d5dd1cf5aa --- /dev/null +++ b/.changeset/rare-pens-exist.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Enable to print the config schema non merged with the `non-merged` flag diff --git a/packages/cli/src/commands/config/schema.ts b/packages/cli/src/commands/config/schema.ts index f9e6573be6..3241615986 100644 --- a/packages/cli/src/commands/config/schema.ts +++ b/packages/cli/src/commands/config/schema.ts @@ -28,19 +28,23 @@ export default async (opts: OptionValues) => { mockEnv: true, }); - const merged = mergeConfigSchemas( - (schema.serialize().schemas as JsonObject[]).map( - _ => _.value as JSONSchema, - ), - ); - - merged.title = 'Application Configuration Schema'; - merged.description = - 'This is the schema describing the structure of the app-config.yaml configuration file.'; + let configSchema: JsonObject | JSONSchema; + if (!opts.nonMerged) { + configSchema = mergeConfigSchemas( + (schema.serialize().schemas as JsonObject[]).map( + _ => _.value as JSONSchema, + ), + ); + configSchema.title = 'Application Configuration Schema'; + configSchema.description = + 'This is the schema describing the structure of the app-config.yaml configuration file.'; + } else { + configSchema = schema.serialize(); + } if (opts.format === 'json') { - process.stdout.write(`${JSON.stringify(merged, null, 2)}\n`); + process.stdout.write(`${JSON.stringify(configSchema, null, 2)}\n`); } else { - process.stdout.write(`${stringifyYaml(merged)}\n`); + process.stdout.write(`${stringifyYaml(configSchema)}\n`); } }; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1fa7fe2964..b56914dfdc 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -365,6 +365,7 @@ export function registerCommands(program: Command) { '--format ', 'Format to print the schema in, either json or yaml [yaml]', ) + .option('--non-merged', 'Enable to print the config schema non merged') .description('Print configuration schema') .action(lazy(() => import('./config/schema').then(m => m.default)));