Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
90 stars 38 forks source link

Bug of model parser. #114

Closed theoolee closed 10 months ago

theoolee commented 10 months ago
image image

Maybe is't not easy to be fixed. But is there a way to access the raw value of the json? Otherwise there would be no way to get the response data.

theoolee commented 10 months ago

And I think the return type of the request method is better to be Future<HttpResponse\<T>> rather than Future\<T>.

Carapacik commented 10 months ago

Send a part of the diagram to make it easier to understand what the error is

theoolee commented 10 months ago

Send a part of the diagram to make it easier to understand what the error is

swagger is here, and you can find a model named AppointmentCalendarPeriodDate, which is generated to a class with single additionalProperties, properties defined in swagger were missing.

theoolee commented 10 months ago

In the parseDataClasses method of swagger_parser/lib/src/parser/parser.dart, the AppointmentCalendarPeriodDate model is added two times to the dataClasses, and one is with parameters, the other is without parameters.

theoolee commented 10 months ago

The side effect of _findType changes _objectClasses and all the classes in it are added to dataClasses at line 636, which causes the repetition.

theoolee commented 10 months ago

The type of property appointmentCalendarPeriodDate is a ref of AppointmentCalendarPeriodDate model, when parsing this property, a wrong AppointmentCalendarPeriodDate is added to _objectClasses, and the real AppointmentCalendarPeriodDate in the dataClasses will be covered later.

{
    "AppointmentCalendarDate": {
      "type": "object",
      "properties": {
        "appointmentCalendarPeriodDate": {
          "type": "object",
          "description": "",
          "allowEmptyValue": false,
          "additionalProperties": {
            "$ref": "#/definitions/AppointmentCalendarPeriodDate"
          }
       }
    }
}