Skip to content

Commit 82ac351

Browse files
committed
feat(mixins-preview): L1 property mixins have typed relationships
1 parent 7f47552 commit 82ac351

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

packages/@aws-cdk/mixins-preview/scripts/spec2mixins/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class L1PropsMixin extends ClassType {
126126
},
127127
});
128128

129-
this.relationshipDecider = new RelationshipDecider(this.resource, db, false);
129+
this.relationshipDecider = new RelationshipDecider(this.resource, db, true, true);
130130
this.converter = TypeConverter.forMixin({
131131
db: db,
132132
resource: this.resource,

tools/@aws-cdk/spec2cdk/lib/cdk/relationship-decider.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ import { ResourceReference } from './reference-props';
55
import { log } from '../util';
66
import { SelectiveImport } from './service-submodule';
77

8-
/**
9-
* We currently disable the relationship on the properties of types because they would create a backwards incompatible change
10-
* by broadening the output type as types are used both in input and output. This represents:
11-
* Relationship counts:
12-
* Resource-level (non-nested): 598
13-
* Type-level (nested): 483 <- these are disabled by this flag
14-
* Total: 1081
15-
* Properties with relationships:
16-
* Resource-level (non-nested): 493
17-
* Type-level (nested): 358
18-
* Total: 851
19-
*/
20-
export const GENERATE_RELATIONSHIPS_ON_TYPES = false;
21-
228
/**
239
* Represents a cross-service property relationship that enables references
2410
* between resources from different AWS services.
@@ -41,7 +27,24 @@ export class RelationshipDecider {
4127
private readonly namespace: string;
4228
public readonly imports = new Array<SelectiveImport>();
4329

44-
constructor(readonly resource: Resource, private readonly db: SpecDatabase, private readonly enableRelationships = true) {
30+
constructor(
31+
readonly resource: Resource,
32+
private readonly db: SpecDatabase,
33+
public readonly enableRelationships = true,
34+
/**
35+
* We currently disable the relationship on the properties of types because they would create a backwards incompatible change
36+
* by broadening the output type as types are used both in input and output. This represents:
37+
* Relationship counts:
38+
* Resource-level (non-nested): 598
39+
* Type-level (nested): 483 <- these are disabled by this flag
40+
* Total: 1081
41+
* Properties with relationships:
42+
* Resource-level (non-nested): 493
43+
* Type-level (nested): 358
44+
* Total: 851
45+
*/
46+
public readonly enableNestedRelationships = false,
47+
) {
4548
this.namespace = namespaceFromResource(resource);
4649
}
4750

@@ -146,7 +149,7 @@ export class RelationshipDecider {
146149
* Checks if a given property needs a flattening function or not
147150
*/
148151
public needsFlatteningFunction(propName: string, prop: Property, visited = new Set<string>()): boolean {
149-
if (!GENERATE_RELATIONSHIPS_ON_TYPES) {
152+
if (!this.enableNestedRelationships) {
150153
return false;
151154
}
152155
if (this.hasValidRelationships(propName, prop.relationshipRefs)) {

tools/@aws-cdk/spec2cdk/lib/cdk/resolver-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DefinitionReference, Property } from '@aws-cdk/service-spec-types';
22
import { expr, Expression, Module, Type } from '@cdklabs/typewriter';
33
import { CDK_CORE } from './cdk';
4-
import { RelationshipDecider, Relationship, GENERATE_RELATIONSHIPS_ON_TYPES } from './relationship-decider';
4+
import { RelationshipDecider, Relationship } from './relationship-decider';
55
import { NON_RESOLVABLE_PROPERTY_NAMES } from './tagging';
66
import { TypeConverter } from './type-converter';
77
import { flattenFunctionNameFromType, propertyNameFromCloudFormation } from '../naming';
@@ -29,7 +29,7 @@ export class ResolverBuilder {
2929
) {}
3030

3131
public buildResolver(prop: Property, cfnName: string, isTypeProp = false): ResolverResult {
32-
const shouldGenerateRelationships = isTypeProp ? GENERATE_RELATIONSHIPS_ON_TYPES : true;
32+
const shouldGenerateRelationships = isTypeProp ? this.relationshipDecider.enableNestedRelationships : true;
3333
const name = propertyNameFromCloudFormation(cfnName);
3434
const baseType = this.converter.typeFromProperty(prop);
3535

0 commit comments

Comments
 (0)