我最近使用了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),但是在任何地方都有测试工具吗?
发布于 2018-04-18 19:52:51
嗯,我想出了这方面的基本知识,一个很小的例子:
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生成的代码是如何测试的。线束在哪里?有一个吗?
https://stackoverflow.com/questions/49886144
复制相似问题