You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please verify that this feature request has NOT been suggested before.
I checked and didn't find a similar feature request
Problem statement
Hi folks,
I used to write tools in C++ with the Qt framework a lot and it would be handy if I could interact with the InvenTree sometimes.
Making REST calls with Qt is quite straightforward to implement "by hand", but I would like to spare (or more exactly make more future-proof) the generation of the exchanged data classes.
When working with Django/InvenTree migrations I started to wonder that some python code must have awareness of the InvenTree/Django objects and their fields. I could write a python script which would do the same thing to generate the C++ classes. This could be ran on each InvenTree release to regenerate the API for the new releases.
I opened this FR to start some brainstorming on this topic because I think there could be some common interests with others.
Another option is that each API endpoint also is self describing. Perform an OPTIONS request against an API endpoint to see the available fields. This is how the web interface (and the app) works, it gets all the field info from the API itself.
The generated code will not be compile-able see: OpenAPITools/openapi-generator#17487
I will submit PR to the openapi-generator soon to fix the issue. Otherwise the methods of the classes generated for models having field called 'valid' needs to be manually renamed/prefixed.
Usage wise it is quite comfy, you could use the API key in the following manner:
@martonmiklos very interesting, this might be worth adding to the documentation for others to benefit from. If there are extra information fields that we need to add to the existing schema, please raise a separate issue for that!
Activity
SchrodingersGat commentedon Apr 5, 2023
The API is not the same as the underlying model structure. But the API is self documenting (at
/api-doc/).FYI I use the the inventree API in a Qt application using the pythonqt bindings.
A C++ API library would be interesting but I'm certainly not going to have any time or interest to develop it.
martonmiklos commentedon Apr 5, 2023
Mhh good point. Are you aware if this api-doc output could be tricked to get json or parsable output?
SchrodingersGat commentedon Apr 5, 2023
Not sure if it can be parsed as JSON. Maybe?
Another option is that each API endpoint also is self describing. Perform an OPTIONS request against an API endpoint to see the available fields. This is how the web interface (and the app) works, it gets all the field info from the API itself.
matmair commentedon Apr 5, 2023
#4178 might help with this - that would output an OpenApi file that can be used to generate client libraries.
martonmiklos commentedon Apr 5, 2023
Thanks guys for your great inputs!
I found an useful library:
https://github.com/qtrest/qtrest
If I manage got gain access to the API endpoints with some parseable format I can write a code generator for this library.
wolflu05 commentedon Apr 6, 2023
Aren't there already some code generators for swagger?
matmair commentedon Apr 6, 2023
Swagger => OpenAPI. They use the open standard (I think they partook in the development - not 100% about that though)
SchrodingersGat commentedon Apr 12, 2023
@martonmiklos I'm going to close this one out as it's out of scope, but keep us posted if you get something working!
martonmiklos commentedon Jan 9, 2024
Some side info for the posterity, I got it rolling with the following methods:
I have not looked into it deeply yet, but I think it would be useful if the InvenTree would generate those fields into the schema.
The generated code will not be compile-able see: OpenAPITools/openapi-generator#17487
I will submit PR to the openapi-generator soon to fix the issue. Otherwise the methods of the classes generated for models having field called 'valid' needs to be manually renamed/prefixed.
Usage wise it is quite comfy, you could use the API key in the following manner:
SchrodingersGat commentedon Jan 10, 2024
@martonmiklos very interesting, this might be worth adding to the documentation for others to benefit from. If there are extra information fields that we need to add to the existing schema, please raise a separate issue for that!