in src/cfn-resource-generator.ts [24:63]
constructor(private readonly typeName: string, private readonly typeDef: TypeInfo, private readonly schema: any) {
this.sanitizedTypeName = sanitizeTypeName(typeName);
// this.resourceAttributes = this.schema.readOnlyProperties ? this.schema.readOnlyProperties.map((prop: string) => prop.replace(/^\/properties\//, '')) : [];
// this.resourceProperties = Object.keys(this.schema.properties).filter(prop => this.resourceAttributes.indexOf(prop) === -1);
this.constructClassName = TypeGenerator.normalizeTypeName(`Cfn${this.sanitizedTypeName}`);
this.propsStructName = TypeGenerator.normalizeTypeName(`${this.constructClassName}Props`);
this.resourceAttributes = new Array<string>();
this.resourceProperties = new Array<string>();
const props = this.schema.properties ?? {};
const attributeNames: string[] = this.schema.readOnlyProperties
? this.schema.readOnlyProperties.map((prop: string) => prop.replace(/^\/properties\//, ''))
: [];
for (const attr of attributeNames) {
const def = props[attr];
if (!def) {
console.warn(`Unresolvable read-only property (attribute) ${typeName}.${attr}`);
continue;
}
// verify that the type of the attribute is a primitive
if (def.type !== 'string' && def.type !== 'number') {
console.warn(`Unsupported type ${JSON.stringify(def)} for read-only property (attribute) ${typeName}.${attr}`);
continue;
}
this.resourceAttributes.push(attr);
}
for (const prop of Object.keys(props)) {
// if this is a read-only property, consider it an attribute
if (attributeNames.includes(prop)) {
continue;
}
this.resourceProperties.push(prop);
}
}