How to use the @aws-cdk/cfnspec.schema.isCollectionProperty function in @aws-cdk/cfnspec

To help you get started, we’ve selected a few @aws-cdk/cfnspec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / tools / cfn2ts / lib / codegen.ts View on Github external
private findNativeType(resourceContext: genspec.CodeName, propSpec: schema.Property, propName?: string): string {
    const alternatives: string[] = [];

    // render the union of all item types
    if (schema.isCollectionProperty(propSpec)) {
      // render the union of all item types
      const itemTypes = genspec.specTypesToCodeTypes(resourceContext, itemTypeNames(propSpec));

      // 'tokenizableType' operates at the level of rendered type names in TypeScript, so stringify
      // the objects.
      const renderedTypes = itemTypes.map(t => this.renderCodeName(resourceContext, t));
      if (!tokenizableType(renderedTypes) && propName !== 'Tags') {
        // Always accept a token in place of any list element (unless the list elements are tokenizable)
        itemTypes.push(genspec.TOKEN_NAME);
      }

      const union = this.renderTypeUnion(resourceContext, itemTypes);

      if (schema.isMapProperty(propSpec)) {
        alternatives.push(`{ [key: string]: (${union}) }`);
      } else {
github aws / aws-cdk / tools / cfn2ts / lib / genspec.ts View on Github external
export function typeDispatch(resourceContext: CodeName, spec: schema.Property, visitor: PropertyVisitor): T {
  const scalarTypes = specTypesToCodeTypes(resourceContext, scalarTypeNames(spec));
  const itemTypes = specTypesToCodeTypes(resourceContext, itemTypeNames(spec));

  if (scalarTypes.length && itemTypes.length) {
    // Can accept both a list and a scalar
    return visitor.visitListOrScalar(scalarTypes, itemTypes);
  } else if (schema.isCollectionProperty(spec)) {
    if (schema.isMapProperty(spec)) {
      if (itemTypes.length > 1) {
        return visitor.visitUnionMap(itemTypes);
      } else {
        return visitor.visitMap(itemTypes[0]);
      }
    } else {
      if (itemTypes.length > 1) {
        return visitor.visitUnionList(itemTypes);
      } else {
        return visitor.visitList(itemTypes[0]);
      }
    }
  } else {
    if (scalarTypes.length > 1) {
      return visitor.visitUnionScalar(scalarTypes);