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

How do I use swagger-codegen cpprest client library code?

本文关键字:代码 客户端 cpprest 何使用 swagger-codegen      更新时间:2023-10-16

我最近使用 swagger-codegen 为我的 swagger 规范生成 cpprest 客户端代码。代码全部编译和链接在我的C++应用程序中膨胀。

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

我已经对使用生成的客户端代码演示的源代码进行了相当广泛的互联网搜索,但无济于事。我还注意到这里有 cpprest 的 swagger-codegen 示例宠物店客户端库:(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';
}
});

我仍然想了解如何测试宠物商店cpprest生成的代码。安全带在哪里?有吗?