首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用swagger-codegen cpprest客户端库代码?

如何使用swagger-codegen cpprest客户端库代码?
EN

Stack Overflow用户
提问于 2018-04-17 19:33:50
回答 1查看 5.5K关注 0票数 9

我最近使用了swagger-codegen来为我的swagger规范生成cpprest客户端代码。所有的代码都在我的C++应用程序中编译和链接。

但是,我如何从我的C++应用程序中实际使用它呢?我似乎已经初始化了ApiClient和ApiConfiguration。但我不清楚如何将getXXX()调用合并到我的API对象(ex: DefaultApi)上。

我做了一个相当广泛的互联网搜索源代码演示使用生成的客户端代码,但没有任何效果。我还注意到这里有用于cpprest的swagger-codegen示例petstore客户端库:(https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/cpprest),但是在任何地方都有测试工具吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-18 19:52:51

嗯,我想出了这方面的基本知识,一个很小的例子:

代码语言:javascript
复制
std::shared_ptr<ApiClient> apiClient(new ApiClient);
std::shared_ptr<ApiConfiguration> apiConfig(new ApiConfiguration);
apiConfig->setBaseUrl("http://example.com/api/v1");
apiClient->setConfiguration(apiConfig);
ExampleApi api(apiClient);
api.getExample().then([=](pplx::task<std::shared_ptr<Example>> example) {
  try {
      std::cout << example.get()->getDescription() << '\n';
  } catch(const std::exception& e) {
      std::cout << "getExample() exception: " << e.what() << '\n';
  }
});

我仍然想了解一下petstore cpprest生成的代码是如何测试的。线束在哪里?有一个吗?

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49886144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档