Skip to content

生成sdk 报错 #112

@jiashiwen

Description

@jiashiwen
import Util;

type @endpoint_host = string
type @protocol = string

model Config {
  endpoint: string,
  protocol: string
}

init(config: Config){
  @endpoint_host = config.endpoint;
  @protocol = config.protocol;
}

model RawGetRequest {
  Key: string,
}

model RawGetResponse{  
	code: number,
	msg: string,
	data: string
}

api rawgetModule(pathname: string, query: RawGetRequest): RawGetResponse {
  __request.protocol = @protocol;
  __request.method = 'POST';
  __request.pathname = `/api/v1/raw/get`;
  __request.headers = {
    host = @endpoint_host,
    content-type = 'application/json; charset=utf-8'
  };
  __request.query = Util.toJSONString(query);  
} returns {
  var result = Util.assertAsMap(Util.readAsJSON(__response.body));

  if (!Util.equalNumber(__response.statusCode, 200)) {
    throw {
      message = `code: ${__response.statusCode}, ${result.code} reason: ${result.msg}`,
      code = `${result.code}`
    };
  }

  if (!Util.assertAsBoolean(result.ok)) {
    throw {
      message = `code: ${result.status}, ${result.code} reason: ${result.msg}`,
      code = `${result.code}`
    };
  }
  return result;
} runtime {
  timeout = 1000 // 10s 的过期时间
}

报错如下

exec error :
SyntaxError: Unexpected token / in JSON at position 110
    at JSON.parse (<anonymous>)
    at CodegenCommand.exec (/Users/jiashiwen/node-v16.13.0-darwin-x64/lib/node_modules/@darabonba/cli/commands/codegen.js:116:22)
    at CommandsApplication.exec (/Users/jiashiwen/node-v16.13.0-darwin-x64/lib/node_modules/@darabonba/cli/lib/app.js:154:13)
    at CommandsApplication.run (/Users/jiashiwen/node-v16.13.0-darwin-x64/lib/node_modules/@darabonba/cli/lib/app.js:34:12)
    at Object.<anonymous> (/Users/jiashiwen/node-v16.13.0-darwin-x64/lib/node_modules/@darabonba/cli/bin/dara.js:45:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

不知道是那句语法错了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions