【问题标题】:How do I use swagger-codegen cpprest client library code?如何使用 swagger-codegen cpprest 客户端库代码?
【发布时间】:2018-09-27 21:29:02
【问题描述】:

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

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

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

【问题讨论】:

    标签: c++ swagger casablanca cpprest-sdk


    【解决方案1】:

    好吧,我为此制定了基础知识,一个简单的例子:

    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 生成的代码。线束在哪里?有吗?

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2023-03-04
      • 2017-02-05
      • 2018-02-11
      • 2017-07-15
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      相关资源
      最近更新 更多