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