How to use the @jsii/spec.isEnumType function in @jsii/spec

To help you get started, we’ve selected a few @jsii/spec 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 / jsii / packages / @jsii / kernel / lib / serialization.ts View on Github external
}
  if (spec.isUnionTypeReference(typeRef.type)) {
    const compoundTypes = flatMap(typeRef.type.union.types, t => serializationType({ type: t }, lookup));
    // Propagate the top-level 'optional' field to each individual subtype
    for (const t of compoundTypes) {
      if (t.typeRef !== 'void') {
        t.typeRef.optional = typeRef.optional;
      }
    }
    return compoundTypes.sort((l, r) => compareSerializationClasses(l.serializationClass, r.serializationClass));
  }

  // The next part of the conversion is lookup-dependent
  const type = lookup(typeRef.type.fqn);

  if (spec.isEnumType(type)) {
    return [{ serializationClass: SerializationClass.Enum, typeRef }];
  }

  if (spec.isInterfaceType(type) && type.datatype) {
    return [{ serializationClass: SerializationClass.Struct, typeRef }];
  }

  return [{ serializationClass: SerializationClass.ReferenceType, typeRef }];
}
github aws / jsii / packages / jsii / lib / validator.ts View on Github external
function _enumMembersMustUserUpperSnakeCase(_: Validator, assembly: spec.Assembly, diagnostic: DiagnosticEmitter) {
    for (const type of _allTypes(assembly)) {
      if (!spec.isEnumType(type)) { continue; }

      for (const member of type.members) {
        if (member.name && member.name !== Case.constant(member.name)) {
          diagnostic(ts.DiagnosticCategory.Error,
            `Enum members must use ALL_CAPS: ${member.name}`);
        }
      }
    }
  }
github aws / jsii / packages / jsii-rosetta / lib / jsii / assemblies.ts View on Github external
Object.values(assembly.types).forEach(type => {
      emitDocs(type.docs, `${assembly.name}.${type.name}`);

      if (spec.isEnumType(type)) {
        type.members.forEach(m => emitDocs(m.docs, `${assembly.name}.${type.name}.${m.name}`));
      }
      if (spec.isClassOrInterfaceType(type)) {
        (type.methods ?? []).forEach(m => emitDocs(m.docs, `${assembly.name}.${type.name}#${m.name}`));
        (type.properties ?? []).forEach(m => emitDocs(m.docs, `${assembly.name}.${type.name}#${m.name}`));
      }
    });
  }