Skip to content

Commit 74cd751

Browse files
rix0rrrgithub-actions
andauthored
fix(cloud-assembly-schema): unconfiguredBehavesLike contains info for multiple versions (#782)
The way it's currently specified, the `unconfiguredBehavesLike` field that's in the Cloud Assembly Schema requires the CLI to know the current major version of the CDK Library to properly evaluate: It looks like `unconfiguredBehavesLike: { v1: ..., v2: ... }` subfields, and that requires the CLI to know whether to look in the `v1` or `v2` subfield (and in the future `v3`, `v4`, etc...). That is unnecessary: since the CDK Library knows its own current version so it could just have communicated `unconfiguredBehavesLike: true` to accurately reflect its current behavior, without the consumer needing to know anything about the version. The CLI code right now is only reading the `v2` field, but that will become inaccurate if we ever release CDKv3. In this PR, we're saying that the `v2` subfield is the "official" location of this value going forward. `v1` should be ignored if present (but is still included to not trip up any JSON Schema validation). This leads to the least amount of interference with the existing ecosystem (no forced upgrade by CDK users and no backwards compatibility path in the CLI to potentially read 2 fields). --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <github-actions@github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 2f1d0c2 commit 74cd751

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/artifact-schema.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export interface FeatureFlagReportProperties {
238238
/**
239239
* Information about every feature flag supported by this library.
240240
*/
241-
readonly flags: Record<string, FeatureFlag>;
241+
readonly flags: { [flagName: string]: FeatureFlag };
242242
}
243243

244244
/**
@@ -273,11 +273,44 @@ export interface FeatureFlag {
273273
readonly explanation?: string;
274274

275275
/**
276-
* The value of the flag if it is unconfigured
276+
* The value of the flag that produces the same behavior as when the flag is not configured at all
277277
*
278-
* @default - No value
278+
*The structure of this field is a historical accident. The type of this field
279+
*should have been boolean, which should have contained the default value for
280+
*the flag appropriate for the *current* version of the CDK library. We are
281+
*not rectifying this accident because doing so
282+
*
283+
* Instead, the canonical way to access this value is by evaluating
284+
* `unconfiguredBehavesLike?.v2 ?? false`.
285+
*
286+
* @default false
287+
*/
288+
readonly unconfiguredBehavesLike?: UnconfiguredBehavesLike;
289+
}
290+
291+
export interface UnconfiguredBehavesLike {
292+
/**
293+
* Historical accident, don't use.
294+
*
295+
* This value may be present, but it should never be used. The actual value is
296+
* in the `v2` field, regardless of the version of the CDK library.
297+
*
298+
* @default - ignore
299+
*/
300+
readonly v1?: any;
301+
302+
/**
303+
* The value of the flag that produces the same behavior as when the flag is not configured at all
304+
*
305+
* Even though it is called 'v2', this is the official name of this field. In
306+
* any future versions of CDK (v3, v4, ...), this field will still be called 'v2'.
307+
*
308+
* The structure of this field is a historical accident. See the comment on
309+
* `unconfiguredBehavesLike` for more information.
310+
*
311+
* @default false
279312
*/
280-
readonly unconfiguredBehavesLike?: { [key: string]: any };
313+
readonly v2?: any;
281314
}
282315

283316
/**

packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,50 @@
505505
"type": "string"
506506
},
507507
"flags": {
508-
"$ref": "#/definitions/Record<string,FeatureFlag>",
509-
"description": "Information about every feature flag supported by this library."
508+
"description": "Information about every feature flag supported by this library.",
509+
"type": "object",
510+
"additionalProperties": {
511+
"$ref": "#/definitions/FeatureFlag"
512+
}
510513
}
511514
},
512515
"required": [
513516
"flags",
514517
"module"
515518
]
516519
},
517-
"Record<string,FeatureFlag>": {
518-
"type": "object"
520+
"FeatureFlag": {
521+
"description": "A single feature flag",
522+
"type": "object",
523+
"properties": {
524+
"recommendedValue": {
525+
"description": "The library-recommended value for this flag, if any\n\nIt is possible that there is no recommended value. (Default - No recommended value.)"
526+
},
527+
"userValue": {
528+
"description": "The value configured by the user\n\nThis is the value configured at the root of the tree. Users may also have\nconfigured values at specific locations in the tree; we don't report on\nthose. (Default - Not configured by the user)"
529+
},
530+
"explanation": {
531+
"description": "Explanation about the purpose of this flag that can be shown to the user. (Default - No description)",
532+
"type": "string"
533+
},
534+
"unconfiguredBehavesLike": {
535+
"description": "The value of the flag that produces the same behavior as when the flag is not configured at all\n\nThe structure of this field is a historical accident. The type of this field\nshould have been boolean, which should have contained the default value for\nthe flag appropriate for the *current* version of the CDK library. We are\nnot rectifying this accident because doing so\n\nInstead, the canonical way to access this value is by evaluating\n`unconfiguredBehavesLike?.v2 ?? false`.",
536+
"default": false,
537+
"$ref": "#/definitions/UnconfiguredBehavesLike"
538+
}
539+
}
540+
},
541+
"UnconfiguredBehavesLike": {
542+
"type": "object",
543+
"properties": {
544+
"v1": {
545+
"description": "Historical accident, don't use.\n\nThis value may be present, but it should never be used. The actual value is\nin the `v2` field, regardless of the version of the CDK library. (Default - ignore)"
546+
},
547+
"v2": {
548+
"description": "The value of the flag that produces the same behavior as when the flag is not configured at all\n\nEven though it is called 'v2', this is the official name of this field. In\nany future versions of CDK (v3, v4, ...), this field will still be called 'v2'.\n\nThe structure of this field is a historical accident. See the comment on\n`unconfiguredBehavesLike` for more information.",
549+
"default": false
550+
}
551+
}
519552
},
520553
"MissingContext": {
521554
"description": "Represents a missing piece of context.",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"schemaHash": "0807b42f8220bdafddeb4dad246a696721ed86e99ac6b13aa83359bab834d60d",
2+
"schemaHash": "4755f1d1fcb2dc25dd6bff0494afa7d86c517274ffebdf2ac2dcb90ad4b899c4",
33
"$comment": "Do not hold back the version on additions: jsonschema validation of the manifest by the consumer will trigger errors on unexpected fields.",
44
"revision": 48
55
}

0 commit comments

Comments
 (0)