Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成sdk 报错 #112

Open
jiashiwen opened this issue Jan 28, 2022 · 2 comments
Open

生成sdk 报错 #112

jiashiwen opened this issue Jan 28, 2022 · 2 comments

Comments

@jiashiwen
Copy link

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)

不知道是那句语法错了

@jiashiwen
Copy link
Author

官方能否给出完整的工程例子?

@ZhaoQi99
Copy link

ZhaoQi99 commented Feb 7, 2022

Try use _request.query = Util.stringify_map_value(query).
You can see below examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants