Jay*_*vas 6 c++ swagger casablanca cpprest-sdk
我最近使用了swagger-codegen为我的swagger规范生成了cpprest客户端代码。该代码全部在我的C ++应用程序中编译和链接。
但是,实际上我该如何在C ++应用程序中使用它呢?我似乎已经初始化了ApiClient和ApiConfiguration。但是我不清楚如何将getXXX()调用合并到我的API对象中(例如:DefaultApi)。
我对源代码进行了相当广泛的互联网搜索,以使用生成的客户端代码进行演示,但无济于事。我还注意到这里有cpprest的swagger-codegen示例petstore客户端库:(https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/cpprest),但是哪里有测试线束吗?
好吧,我为此制定了基础知识,一个简单的例子:
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';
}
});
Run Code Online (Sandbox Code Playgroud)
我仍然想了解如何测试 petstore cpprest 生成的代码。马具在哪儿?有吗?
| 归档时间: |
|
| 查看次数: |
2478 次 |
| 最近记录: |