Skip to content

error when running generator #110

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

Closed
SDP190 opened this issue Jan 13, 2021 · 4 comments
Closed

error when running generator #110

SDP190 opened this issue Jan 13, 2021 · 4 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@SDP190
Copy link

SDP190 commented Jan 13, 2021

Hi I am getting an error when running generator for this json spec:
(partial)

 "RouteViewModel": {
      "type": "object",
      "description": "Stops for route",
      "required": [
        "routeId",
        "status"
      ],
      "properties": {
        "routeId": {
          "type": "string",
          "description": "Route Id",
          "format": "guid"
        },
        "description": {
          "type": "string",
          "description": "Route description"
        },
        "firstStop": {
          "description": "First Stop",
          "allOf": [
            {
              "$ref": "#/definitions/StopViewModel"
            }
          ]
        },
        "status": {
          "description": "Route Status",
          "allOf": [
            {
              "$ref": "#/definitions/RouteStatusEnum"
            }
          ]
        },
        "startLocation": {
          "$ref": "#/definitions/WarehouseViewModel"
        },
        "endLocation": {
          "$ref": "#/definitions/WarehouseViewModel"
        }
      }
    },
    "StopViewModel": {
      "type": "object",
      "description": "Stop in a route",
      "required": [
        "stopId",
        "status"
      ],
      "properties": {
        "stopId": {
          "type": "string",
          "description": "Stop Id",
          "format": "guid"
        },
        "status": {
          "description": "Status of the stop",
          "allOf": [
            {
              "$ref": "#/definitions/RouteStopStatusEnum"
            }
          ]
        },
        "companyName": {
          "type": "string",
          "description": "Company Name"
        },
        "address": {
          "description": "Company Address",
          "allOf": [
            {
              "$ref": "#/definitions/AddressViewModel"
            }
          ]
        },
        "contact": {
          "description": "Contact in company",
          "allOf": [
            {
              "$ref": "#/definitions/ContactViewModel"
            }
          ]
        },
        "nextStop": {
          "description": "Next Stop",
          "allOf": [
            {
              "$ref": "#/definitions/StopViewModel"
            }
          ]
        },
        "note": {
          "type": "string"
        },
        "boxes": {
          "type": "array",
          "description": "Boxes to deliver",
          "items": {
            "$ref": "#/definitions/BoxViewModel"
          }
        },
        "items": {
          "type": "array",
          "description": "Items to deliver",
          "items": {
            "$ref": "#/definitions/ItemViewModel"
          }
        },
        "photos": {
          "type": "array",
          "description": "General photos of the stop",
          "items": {
            "$ref": "#/definitions/PhotoViewModel"
          }
        }
      }
    },
    

Error Output:

Could not generate `fromJson` code for `firstStop`.
To support the type `Null` 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:first_app/swagger/generated/erpAPI.swagger.dart:262:14
    ╷
262 │   final Null firstStop;
    │ 

As seen in the output the generator somehow converts "RouteViewModel"=>"firstStop" to type Null. and then it throws error that it cant handle such a type.
This api spec file was generated from an AspNetCore API project via a swagger plugin package. The spec version is swagger 2.0

Things to note (Not sure whether its causing the error or not):
1- Usage of allOf
2- Usage of ref within allOf
3- StopViewModel "nextStop" property has a circular reference to itself (allOf: [ {"$ref":"#/definitions/StopViewModel"} ])

@houdinihacker
Copy link
Collaborator

allOf, anyOf etc., currently is not supported. I'm working on major PR to fix this issue but do not have ETA.

@houdinihacker houdinihacker added bug Something isn't working good first issue Good for newcomers labels Jan 15, 2021
@houdinihacker houdinihacker self-assigned this Jan 15, 2021
@WahdanZ
Copy link

WahdanZ commented Feb 5, 2021

also not working with oneOf

@point-source
Copy link

I am also running into this issue with properties that have no "type" descriptor such as this:

"properties": {
                    "applicationOptions": {
                        "nullable": true
                    },
                    "clientcode": {
                        "type": "string",
                        "nullable": true
                    },
                },

Note that "clientcode" is of type "string" while "applicationOptions" is unspecified. Reading through the discussion here, it seems that it is up to the developer of the code generator to choose how to handle this case since it technically means that "applicationOptions" will accept any type of object.

I see a few possible options:

  • Set ambiguous types to dynamic (which will likely turn into strings when parsed back to json)
  • Cast ambiguous types to string (similar to above but more obvious / predictable)
  • Allow the user to set an ambiguous type override in the build.yaml

Regardless of which option we go with, it should probably be an optional behavior as part of the build.yaml options.

Restarting the discussion here so that hopefully we can arrive at a conclusion that can be used to build a pr.

@Vovanella95
Copy link
Collaborator

Hi @WahdanZ , @point-source , @volang

Too many issues in one issue. I've generated your examples and looks like they are generated well. Support of allof will be implemented soon. Currently it's not supported.

Please create separate issues if you still have ones. Thanks!

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

No branches or pull requests

5 participants