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
94 stars 43 forks source link

Bug: AllOf not processed correctly #72

Closed n-gras closed 1 year ago

n-gras commented 1 year ago

Hi! Thanks again for your great work on this tool :) I've run into another issue, with objects that use/inherit from other objects. They are translated as using 'allOf' in swagger.json. I've copied a small sample of this below.

"CreateUserRequest": {
        "required": [
          "friendlyName",
          "userId"
        ],
        "type": "object",
        "properties": {
          "userId": {
            "type": "integer",
            "format": "int32"
          },
          "friendlyName": {
            "minLength": 1,
            "type": "string"
          }
        },
        "additionalProperties": false
      },

 "CreateUserWithPhoneRequest": {
        "required": [
          "simCardNumber"
        ],
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/CreateUserRequest"
          }
        ],
        "properties": {
          "simCardNumber": {
            "minLength": 1,
            "type": "string"
          }
        },
        "additionalProperties": false
      },

The created file for the CreateUserWithPhoneRequest looks like:

import 'package:freezed_annotation/freezed_annotation.dart';

part 'create_user_with_phone_request.freezed.dart';
part 'create_user_with_phone_request.g.dart';

@Freezed()
class CreateUserWithPhoneRequest with _$CreateUserWithPhoneRequest {
  const factory CreateUserWithPhoneRequest({
    required String simCardNumber,
  }) = _CreateUserWithPhoneRequest;

  factory CreateUserWithPhoneRequest.fromJson(Map<String, dynamic> json) =>
      _$CreateUserWithPhoneRequestFromJson(json);
}

In short, the inherited class is missing the fields from the base class.

Carapacik commented 1 year ago

Thanks for issue, I found an approximate place with the problem, I'll try to fix it the other day.

Carapacik commented 1 year ago

Try latest version

n-gras commented 1 year ago

Unfortunately, it seems to have no effect on my generated classes.

Carapacik commented 1 year ago

I don't even know what the problem is then. I have everything working successfully on your example.

n-gras commented 1 year ago

I've emailed you a part of the file that is causing the issue, hopefully that helps.