schemaWithDefaultDialect static method

Map<String, dynamic> schemaWithDefaultDialect(
  1. Map<String, dynamic> schema,
  2. String version
)

Return a copy of schema annotated with the 2020-12 $schema dialect when (a) the negotiated version pins a default dialect and (b) the schema does not already declare its own $schema. Free-form schemas that already carry a $schema — or any schema under an older negotiated revision — are returned unchanged. Non-mutating: the input map is never modified.

Implementation

static Map<String, dynamic> schemaWithDefaultDialect(
  Map<String, dynamic> schema,
  String version,
) {
  final dialect = defaultSchemaDialect(version);
  if (dialect == null || schema.containsKey(r'$schema')) {
    return schema;
  }
  return <String, dynamic>{r'$schema': dialect, ...schema};
}