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

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

Wrong generation when definigion is an array of objects #108

Closed Vovanella95 closed 3 years ago

Vovanella95 commented 3 years ago

Wrong generation when definigion is an array of objects

PKIE commented 3 years ago

Same issue here. Tried with 1.6.8 Sample openapi schema openapi.txt Array type definition is:

"ListCustomItem": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/CustomItem"
  }
}

As a result the CustomItem is fine, but ListCustomItem generated code is empty:

@JsonSerializable(explicitToJson: true)
class ListCustomItem {
  ListCustomItem();

  factory ListCustomItem.fromJson(Map<String, dynamic> json) =>
      _$ListCustomItemFromJson(json);

  static const fromJsonFactory = _$ListCustomItemFromJson;
  static const toJsonFactory = _$ListCustomItemToJson;
  Map<String, dynamic> toJson() => _$ListCustomItemToJson(this);
}
ListCustomItem _$ListCustomItemFromJson(Map<String, dynamic> json) {
  return ListCustomItem();
}

Map<String, dynamic> _$ListCustomItemToJson(ListCustomItem instance) =>
    <String, dynamic>{};
fryette commented 3 years ago

@PKIE As a temporary solution please use https://github.com/epam-cross-platform-lab/swagger-dart-code-generator#response-override-value-map-for-requests-generation

PKIE commented 3 years ago

Thank you @fryette Do you know if there is a way to override types for array type properties?

PKIE commented 3 years ago

OK, I managed to change the schema generator (probably it was buggy, and now instead creating new ListCustomItem definition it simply defines the response (or internal array) as array of type

So thanks for help, and sorry for bugging ;)