Merge pull request #31303 from Dharma-09/fix-yaml-merge-support

Enable YAML merge keys in yamlPlaceholderResolver
This commit is contained in:
Fredrik Adelöw
2025-11-04 12:56:57 +01:00
committed by GitHub
7 changed files with 43 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': minor
---
Enable YAML merge keys in yamlPlaceholderResolver
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog-backend': minor
'@backstage/plugin-catalog-node': minor
---
Make YAML merge (<<:) support configurable in the Backstage Catalog instead of always being enabled
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog-backend': minor
'@backstage/plugin-catalog-node': minor
---
Enable YAML merge keys in yamlPlaceholderResolver
@@ -142,9 +142,13 @@ export async function yamlPlaceholderResolver(
params.emit(processingResult.refresh(`url:${url}`));
// YAML merge support enabled by default
const enableYamlMerge = false;
const parseOptions = { merge: enableYamlMerge };
let documents: yaml.Document.Parsed[];
try {
documents = yaml.parseAllDocuments(content).filter(d => d);
documents = yaml.parseAllDocuments(content, parseOptions).filter(d => d);
} catch (e) {
throw new Error(
`Placeholder \$${params.key} failed to parse YAML data at ${params.value}, ${e}`,
+7
View File
@@ -313,8 +313,15 @@ export function locationSpecToMetadataName(location: LocationSpec_2): string;
export function parseEntityYaml(
data: string | Buffer,
location: LocationSpec_2,
options?: ParseEntityYamlOptions,
): Iterable<CatalogProcessorResult>;
// @public
export interface ParseEntityYamlOptions {
// (undocumented)
enableYamlMerge?: boolean;
}
// @public (undocumented)
export type PlaceholderResolver = (
params: PlaceholderResolverParams,
+1 -1
View File
@@ -24,4 +24,4 @@ export type {
LocationAnalyzer,
ScmLocationAnalyzer,
} from './types';
export { parseEntityYaml } from './parse';
export { parseEntityYaml, type ParseEntityYamlOptions } from './parse';
@@ -21,6 +21,15 @@ import { LocationSpec } from '@backstage/plugin-catalog-common';
import { CatalogProcessorResult } from '../api/processor';
import { processingResult } from '../api/processingResult';
/**
* Options for parsing entity YAML files.
*
* @public
*/
export interface ParseEntityYamlOptions {
enableYamlMerge?: boolean;
}
/**
* A helper function that parses a YAML file, properly handling multiple
* documents in a single file.
@@ -40,12 +49,16 @@ import { processingResult } from '../api/processingResult';
export function* parseEntityYaml(
data: string | Buffer,
location: LocationSpec,
options?: ParseEntityYamlOptions,
): Iterable<CatalogProcessorResult> {
const parseOptions = { merge: options?.enableYamlMerge ?? false };
let documents: yaml.Document.Parsed[];
try {
documents = yaml
.parseAllDocuments(
typeof data === 'string' ? data : data.toString('utf8'),
parseOptions,
)
.filter(d => d);
} catch (e) {