Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case spec.PrimitiveType.Json: return [{ serializationClass: SerializationClass.Json, typeRef }];
case spec.PrimitiveType.Boolean:
case spec.PrimitiveType.Number:
case spec.PrimitiveType.String:
return [{ serializationClass: SerializationClass.Scalar, typeRef }];
}
throw new Error('Unknown primitive type');
}
if (spec.isCollectionTypeReference(typeRef.type)) {
return [{
serializationClass: typeRef.type.collection.kind === spec.CollectionKind.Array ? SerializationClass.Array : SerializationClass.Map,
typeRef
}];
}
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 }];
}
public get unionOfTypes(): TypeReference[] | undefined {
if (!jsii.isUnionTypeReference(this.spec)) {
return undefined;
}
return this.spec.union.types.map(t => new TypeReference(this.system, t));
}
}
function _collectTypeReferences(type: spec.TypeReference): void {
if (spec.isNamedTypeReference(type)) {
typeReferences.push(type);
} else if (spec.isCollectionTypeReference(type)) {
_collectTypeReferences(type.collection.elementtype);
} else if (spec.isUnionTypeReference(type)) {
type.union.types.forEach(_collectTypeReferences);
}
}
}