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

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

[BUG] Cannot generate fromJson error #735

Open konsultaner opened 7 months ago

konsultaner commented 7 months ago

Describe the bug The following yaml file is just a very condenced part of my very big swagger code. The file renders well except of this little part below. The isue seems that the response type has an array of objects.

I can either remove this

### ISSUE:
properties:
  articleIds:
    type: array

or this:

### ISSUE:
condition:
  type: object
    properties:
      type:
        type: string

to get it to render the file. If I replace the first ### ISSUE with the second, it will also work. seems like the code generator expects the same signature in both parts. I expect it to extend the model.

To Reproduce

openapi: 3.0.1
info:
  title: Genertating Error
  version: '1.0.0'
paths:
  /test:
    post:
      operationId: 'test'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: array
                items:
                  allOf:
                    - $ref: '#/components/schemas/Error'
                  type: object
                  ### ISSUE:
                  properties:
                    articleIds:
                      type: array
components:
  schemas:
    Error:
      type: object
      properties:
        field:
          type: string
        ### ISSUE:
        condition:
          type: object
          properties:
            type:
              type: string

results in

Could not generate `fromJson` code for `condition`.
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:test/api/error.swagger.dart:119:43
    ╷
119 │   final TestPost$Response$Item$Condition? condition;
    │                                           ^^^^^^^^^
    ╵

Expected behavior Should generate code without the error

Swagger specification link Link to swagger/OpenApi documentation

Library version used:


environment:
  sdk: '>=3.3.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  chopper: ^7.1.1+1
  json_annotation: ^4.8.1

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.1
  test: ^1.24.9
  build_runner: ^2.4.8
  chopper_generator: ^7.1.1
  json_serializable: ^6.7.1
  swagger_dart_code_generator: ^2.15.1

flutter:
  uses-material-design: true
konsultaner commented 7 months ago

maybe related to #721