function behaviorExists()

in compiler/src/steps/validate-model.ts [716:739]


  function behaviorExists (type: (model.Request | model.Interface), behavior: model.TypeName): boolean {
    // Does the type have this behavior?
    for (const b of (type.behaviors ?? [])) {
      if (sameTypeName(b.type, behavior)) {
        return true
      }
    }

    // Does a parent have this behavior?
    if (type.inherits != null) {
      const parentDef = getTypeDef(type.inherits.type)
      if (parentDef == null) {
        modelError(`No type definition for parent '${fqn(type.inherits.type)}'`)
        return false
      }
      if (parentDef.kind === 'request' || parentDef.kind === 'interface') {
        if (behaviorExists(parentDef, behavior)) {
          return true
        }
      }
    }

    return false
  }