Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: primitive metadata values cannot be loaded in jsii languages (#121)
In aws/aws-cdk#31041, the CDK started emitting booleans and numbers as metadata values. However, since these types are not officially declared in the schema, jsii runtime type checking prevents loading them: ```console [ERROR] ├── 🛑 Failing value is a boolean [ERROR] │ true [ERROR] ╰── 🔍 Failure reason(s): [ERROR] ├─ [as string] Value is not a string [ERROR] ├─ [as array<aws-cdk-lib.cloud_assembly_schema.Tag>] Value is not an array [ERROR] ├─ [as aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry] Value is not an object [ERROR] ╰─ [as aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry] Value is not an object ``` Fixes aws/jsii#4742 > Note that releasing this will immediately resolve the above issue, no cdk release needed. It does bump the schema version, which we can update at will. ## FAQ ### If the types are not allowed in the schema, how can a manifest with them be written? Actually, these types **are** allowed in the schema, in the json schema that is: https://github.com/cdklabs/cloud-assembly-schema/blob/f5ae537437531364646e7515e5286e21583c8421/schema/cloud-assembly.schema.json#L131-L133 This free form data is added to the json schema in order to support calls to `node.addMetadata(key: string, value: any)`, as defined in the `constructs` API. However, this type was intentionally left out of the type declaration: https://github.com/cdklabs/cloud-assembly-schema/blob/f5ae537437531364646e7515e5286e21583c8421/projenrc/update-schema.ts#L79-L89 I'm fairly certain the comment is not applicable anymore, because we don't run jsii compatibility checks on the schema (we just bump it on every change). In practice, I think we can probably get rid of this patching and just type metadata entry values as `any` - but that seems like a bigger change I don't want to go into right now. ### If such manifests cannot be loaded, how does synth work? Because during synth, loading the assembly using the `Manifest` class happens solely inside the javascript space, it doesn't callback to java land. This problem presents itself **only when** directly using the java `Manifest` class and invoking the `loadAssemblyManifest` function on a manifest produced by `app.synth()`.
- Loading branch information