Hi Paul there isn’t much of a getting-started guide for QT but there should be 
one.  Maybe you can help with a PR to the repository?

Getting started should be simple, but here’s a quick tutorial to help out.

* Upon generation, you will have a set of files created—the ones ending in 
“Api” are the classes used to call the server.  Every method in there 
corresponds, through “operationId” in your spec and includes the parameters for 
calling it
* A Model class is created for each schema definition in your swagger file.  
These are input/outputs for the calls to the api classes
* Each API call executes a function which calls back to a slot in your 
application.  To receive the callback, you’ll need to connect your listener to 
the appropriate callback.

For example this sample client:

https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/qt5cpp
 
<https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/qt5cpp>

To get a “pet by ID” you would
* include SWGPetApi.h in your class making the call
* instantiate the SWGPetApi class like such:

SWGPetApi * api = new SWGPetApi();

* Connect the SWGPetApi instance to your app like such:

this->connect(api, getPetByIdSignal(SWGPet*), this, getPetCallback(SWGPet* pet)

* Call the getPetById(qint64 pet_id); method
* Your function “getPetByIdCallback(SWGPet* pet)” will be called by the api 
class

There are some other convenience features, such as serializing the models to 
JSON and back, for example you can write a model to JSON like this:

SWGPet pet;
pet.setId(300);

qDebug() << pet.asJson();

and also instantiate objects from json:

QString json("{\"id\":3}");

// populate the object from JSON
pet.fromJson(json);
etc.

Tony

> On Feb 6, 2017, at 12:44 AM, Paul Masri-Stone <[email protected]> wrote:
> 
> Hi, bit of a noob question.
> 
> I've defined an API with Swagger - awesome tool - and I'm using the code 
> generation tool to generate Qt C++ clientside code. Is there a guide to 
> getting started with it or some examples out there using it? I've looked 
> through all the generated classes, but I don't get how to use them. Rather 
> than spend a day or two scratching my head, are there resources I can look at?
> 
> Thanks
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Swagger" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to