Skip to content

Commit 40e8c26

Browse files
authored
chore: update metadata_updater to skip some L2 constructs from being injectable (#34463)
### Issue # (if applicable) N/A ### Reason for this change Release was failing because when metadata_updater job got executed to automatically mark L2 constructs as injectables, it failed to update some constructs because they do not follow the normal patterns of L2 constructors. ### Description of changes - Added skip logic to skip some L2 constructs from being marked as Injectables. - Applied the injectables logic manually to `RootResource` since it's constructor does not follow the common constructors pattern for L2s, and should support the injectable logic. - Skipped `lib/function-base.LatestVersion`, as in my opinion it does not need to support the injectable feature. The constructor does not accept any props, and so It does not support any injected property injection. - Added some changes to the metadata_updater tool itself to fix some linter errors. ### Description of how you validated changes executed the metadata_updater job locally to verify the generated L2 constructs. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 967ee9d commit 40e8c26

File tree

7 files changed

+196
-56
lines changed

7 files changed

+196
-56
lines changed

packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Toke
2121
import { ValidationError } from '../../core/lib/errors';
2222
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
2323
import { propertyInjectable } from '../../core/lib/prop-injectable';
24+
import { applyInjectors } from '../../core/lib/prop-injectors-helpers';
2425
import { APIGATEWAY_DISABLE_CLOUDWATCH_ROLE } from '../../cx-api';
2526

2627
const RESTAPI_SYMBOL = Symbol.for('@aws-cdk/aws-apigateway.RestApiBase');
@@ -1140,6 +1141,7 @@ export enum RestApiMode {
11401141
}
11411142

11421143
class RootResource extends ResourceBase {
1144+
public static readonly PROPERTY_INJECTION_ID: string = 'aws-cdk-lib.aws-apigateway.RootResource';
11431145
public readonly parentResource?: IResource;
11441146
public readonly api: RestApiBase;
11451147
public readonly resourceId: string;
@@ -1152,6 +1154,10 @@ class RootResource extends ResourceBase {
11521154

11531155
constructor(api: RestApiBase, props: ResourceOptions, resourceId: string) {
11541156
super(api, 'Default');
1157+
props = applyInjectors(RootResource.PROPERTY_INJECTION_ID, props, {
1158+
scope: api,
1159+
id: resourceId,
1160+
});
11551161
// Enhanced CDK Analytics Telemetry
11561162
addConstructMetadata(this, resourceId);
11571163

packages/aws-cdk-lib/core/lib/prop-injectable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct, IConstruct } from 'constructs';
2-
import { applyInjectors } from './private/prop-injectors-helpers';
2+
import { applyInjectors } from './prop-injectors-helpers';
33

44
interface PropertyInjectableConstructConstructor {
55
readonly PROPERTY_INJECTION_ID: string;

packages/aws-cdk-lib/core/lib/private/prop-injectors-helpers.ts renamed to packages/aws-cdk-lib/core/lib/prop-injectors-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct, IConstruct, Node } from 'constructs';
2-
import { InjectionContext, IPropertyInjector, PropertyInjectors } from '../prop-injectors';
2+
import { InjectionContext, IPropertyInjector, PropertyInjectors } from './prop-injectors';
33

44
/**
55
* This symbol is needed to identify PropertyInjectors.

packages/aws-cdk-lib/core/lib/prop-injectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct, IConstruct } from 'constructs';
2-
import { PROPERTY_INJECTORS_SYMBOL } from './private/prop-injectors-helpers';
2+
import { PROPERTY_INJECTORS_SYMBOL } from './prop-injectors-helpers';
33

44
/**
55
* This defines the values needed for Injection.

packages/aws-cdk-lib/core/test/prop-injectors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Construct } from 'constructs';
22
import { Annotations, Resource, Stack, Stage } from '../lib';
33
import { App } from '../lib/app';
4-
import { applyInjectors, findInjectorFromConstruct } from '../lib/private/prop-injectors-helpers';
54
import { propertyInjectable } from '../lib/prop-injectable';
65
import { InjectionContext, IPropertyInjector, PropertyInjectors } from '../lib/prop-injectors';
6+
import { applyInjectors, findInjectorFromConstruct } from '../lib/prop-injectors-helpers';
77

88
// Define Injectors for our testing
99
class DoNothingInjector implements IPropertyInjector {

0 commit comments

Comments
 (0)