I've recently used swagger-codegen to generate the cpprest client code for my swagger spec. The code all compiles and links swell in my C++ app.
But, how do I actually use it from my C++ application? I've seem to have initialized the ApiClient and ApiConfiguration. But it's not clear to me how to incorporate the getXXX() call on my API object (ex: DefaultApi).
I've done a rather extensive internet search for source code demonstrating using the generated client code, but to no avail. I've also noted there is the swagger-codegen sample petstore client library for cpprest here: (https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/cpprest), but is there a test harness for it anywhere?
In the Swagger Editor toolbar, select Generate Client > Python to download a client written in Python. Our example code is written in Python. Swagger Editor supports over 50 other languages that you can use for the client interface you develop.
Download the Swagger Codegen JAR File Download the latest version of the Swagger Codegen JAR 2.3. 0+. Windows users can use Invoke-WebRequest in PowerShell 3.0+ (e.g., Invoke-WebRequest -OutFile swagger-codegen-cli. jar http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar).
Swagger Codegen is available for download in the GitHub repository, or can be generated for any new or existing OpenAPI-defined API in the integrated SwaggerHub platform.
Well, I worked out the basics for this, a trivial example:
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';
}
});
I'd still like to learn how the petstore cpprest generated code is tested. Where's the harness? Is there one?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With