sdrangel icon indicating copy to clipboard operation
sdrangel copied to clipboard

Swagger code gen incorrect for arrays of integer

Open srcejon opened this issue 1 year ago • 2 comments

It seems the swagger code generation for arrays of integers is incorrect.

As an example (but there are others), in VORLocalizer.yaml, we have:

columnIndexes:
  type: array
  items:
    type: integer

When getting feature settings through the Swagger webpage, the array returned is always empty:

"columnIndexes": [],

This can be fixed by changing the generated code SWGVorLocalizerSettings.cpp from:

    toJsonArray((QList<void*>*)column_indexes, obj, "columnIndexes", "");

To:

    toJsonArray((QList<void*>*)column_indexes, obj, "columnIndexes", "qint32");

But this fix obviously needs to be done in the generator.

(Arrays of strings work ok - they have the last parameter set to "QString")

I notice many other examples of arrays in the yaml files actually uses arrays of structures with a single number/integer element - was that a workaround to this, perhaps? That works, but obviously a little less efficient.

srcejon avatar Oct 24 '23 20:10 srcejon

Looking at the code gen, it sort of looks like this template is used to generate the code:

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache

But the code isn't exactly the same, so I'm not quite sure.

That template has:

 toJsonArray((QList<void*>*){{name}}, obj, "{{baseName}}", "{{complexType}}");

Which suggests the complexType parameter isn't being set to qint32.

srcejon avatar Oct 24 '23 21:10 srcejon

Looks like an upstream bug (https://github.com/swagger-api) with swagger-codegen, as I see the same problem using that.

Have added: https://github.com/swagger-api/swagger-codegen/issues/12256

srcejon avatar Oct 25 '23 09:10 srcejon