Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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 }];
}
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}`);
}
}
}
}
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}`));
}
});
}