epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
256 stars 116 forks source link

[BUG] Generator produces `InvalidType` #712

Closed FaFre closed 7 months ago

FaFre commented 7 months ago

Describe the bug Generator produces InvalidType and fails with:

[SEVERE] json_serializable on lib/src/api/openapi.swagger.dart:

Could not generate `fromJson` code for `property`.
To support the type `InvalidType` you can:
* Use `JsonConverter`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:wikibase/src/api/openapi.swagger.dart:3196:38
     ╷
3196 │   final Statement$Response$Property? property;
     │                                      ^^^^^^^^
     ╵

Swagger specification link https://doc.wikimedia.org/Wikibase/master/js/rest-api/openapi.json

Library version used: 2.14.2

Vovanella95 commented 7 months ago

Hi @FaFre , thanks for raising issue. Will take a look into it soon!

tofylion commented 7 months ago

I also have this issue. However, I don't get any error. The generation is successful, but the generated code has InvalidType.

JaccMirac commented 7 months ago

I also have this issue. I am getting a similar error.

[SEVERE] json_serializable on lib/src/generated/api/backend_api.swagger.dart:

Could not generate `fromJson` code for `type`.
To support the type `InvalidType` you can:
* Use `JsonConverter`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:ideal/src/generated/api/backend_api.swagger.dart:7523:64
     ╷
7523 │   final enums.PairingList$Item$Paired$UserAttachments$ItemType type;
     │                                                                ^^^^
     ╵

If you need, here's also my specification, so you can compare. This may be a similar issue. https://api.develop.maxi-ideal.com/api-yaml

FaFre commented 7 months ago

I also tried it with version 2.12.2 as it seems to have fixed previously reported type errors but it leads to the same result unfortunately.

Vovanella95 commented 7 months ago

Hi @FaFre , @JaccMirac !

I've tried to fix your issue, but your swagger is too complex. We're not gonna support it. Feel free to contribute.

Your swagger contains "Statement" model in multiple places. Also your swagger use allOf inside of allOf inside of allOf. Our generator is not created for such over-linked allOf swagger files, sorry :(

FaFre commented 7 months ago

@Vovanella95 Do you have any tips on how to simplify the swagger file?

Vovanella95 commented 7 months ago

Hi @FaFre , you can put all schemas from responses to schemas and try to regenerate. Also you can try to rid of allOf

Vovanella95 commented 7 months ago

@FaFre I can support with this if you will have difficulties