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
97 stars 45 forks source link

Type generation #224

Closed XanderD99 closed 4 months ago

XanderD99 commented 5 months ago

Steps to reproduce

create openapi spec with a path like

  /nearby:
    get:
      summary: Get nearby places
      tags:
        - Generic
        - Locations
      responses:
        '200':
          description: Return everything nearby
          content:
            application/json:
              schema:
                type: object
                properties:
                  locations:
                    type: array
                    items:
                      $ref: '#/components/schemas/Location'

run swagger parsert

Expected results

typed reponse schema for the response with properties

@Freezed()
class GetNearbyResponse with _$GetNearbyResponse {
  const factory GetNearbyResponse({
    required List<Locations> locations,
  }) = _GetNearbyResponse;

  factory GetNearbyResponse.fromJson(Map<String, Object?> json) => _$GetNearbyResponseFromJson(json);
}

Actual results

response class with no child parameteres

@Freezed()
class GetNearbyResponse with _$GetNearbyResponse {
  const factory GetNearbyResponse() = _GetNearbyResponse;

  factory GetNearbyResponse.fromJson(Map<String, Object?> json) => _$GetNearbyResponseFromJson(json);
}

Your OpenApi snippet

/nearby: get: summary: Get nearby places tags:

Code sample

No response

Logs

No response

Dart version and used packages versions

Dart version ```console Dart SDK version: 3.3.3 (stable) (Tue Mar 26 14:21:33 2024 +0000) on "macos_arm64"```
Packages version ```console ^1.17.2 ```
StarProxima commented 4 months ago

@XanderD99 Hi, this should be fixed in the latest version, can you test it with your examples?