eachAPI()

in lib/generator.js [2150:2213]


  eachAPI(ast, level, sse = false) {
    // if (ast.annotation) {
    //   this.emit(`${_anno(ast.annotation.value)}\n`, level);
    // }
    let comments = DSL.comment.getFrontComments(this.comments, ast.tokenRange[0]);
    this.visitComments(comments, level);
    this.visitAnnotation(ast.annotation, level, false);
    const apiName = _avoidKeywords(_name(ast.apiName));
    if(!ast.annotation || !ast.annotation.value) {
      this.emit('/**\n', level);
    }
    
    this.visitParamsType(ast.params, level);
    this.visitReturnType(ast, level);
    this.emit(' */', level);
    this.emit('\n');


    this.emit(`public function ${apiName}`, level);
    this.visitParams(ast.params, level);
    this.emit('\n');
    this.emit('{\n', level);
    let baseLevel = ast.runtimeBody ? level + 2 : level;
    // api level
    if (ast.runtimeBody) {
      this.visitRuntimeBefore(ast.runtimeBody, level + 1);
    }

    // temp level
    this.visitAPIBody(ast.apiBody, baseLevel + 1);



    if(sse && ast.runtimeBody) {
      this.emit('$_runtime[\'stream\'] = true;\n', baseLevel + 1);
    }
    this.emit('$_response = Dara::send($_request', baseLevel + 1);


    if (ast.runtimeBody) {
      this.emit(', $_runtime');
    }
    if(sse && !ast.runtimeBody) {
      this.emit(', [ \'stream\' => true, ]');
    }
    this.emit(');\n');

    if (ast.runtimeBody) {
      this.emit('$_lastRequest = $_request;\n', baseLevel + 1);
      this.emit('$_lastResponse = $_response;\n', baseLevel + 1);
    }

    if (ast.returns) {
      this.visitReturnBody(ast.returns, baseLevel + 1);
    } else {
      this.visitDefaultReturnBody(baseLevel + 1);
    }

    if (ast.runtimeBody) {
      this.visitRuntimeAfter(ast.runtimeBody, level + 1);
    }

    this.emit('}\n', level);
  }