Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot generate fromJson error #735

Open
konsultaner opened this issue Mar 8, 2024 · 1 comment
Open

[BUG] Cannot generate fromJson error #735

konsultaner opened this issue Mar 8, 2024 · 1 comment
Assignees
Labels
bug Something isn't working Triage needed

Comments

@konsultaner
Copy link

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 konsultaner added bug Something isn't working Triage needed labels Mar 8, 2024
@konsultaner
Copy link
Author

maybe related to #721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Triage needed
Projects
None yet
Development

No branches or pull requests

3 participants