gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
112 stars 29 forks source link

json parsing returns wrong Set when `uniqueItems` is enabled. #115

Open zellidev0 opened 8 months ago

zellidev0 commented 8 months ago

Description of the bug

Generating dart code from a swagger json that has a uniqueItems attribute set to true for a List automatically converts it to a Set while parsing. But the parsing fails because a json List is not a Set.

  "experts": {
                        "uniqueItems": true,
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },

this part gets a json parsing like that:

 json[r'experts'] is Set
            ? (json[r'experts'] as Set).cast<String>()
            : const {},

because the returned Json is never a Set, the result is always empty.

Steps to reproduce

minimal json:

{
    "openapi": "3.0.1",
    "info": {
        "title": "my-service",
        "version": "1.0"
    },
    "servers": [
        {
            "url": "/my-service"
        }
    ],
    "security": [
        {
            "Authorization": []
        }
    ],
    "paths": {
        "/api/v2/subscription/cancel": {
            "delete": {
                "tags": [
                    "subscription-v-2-controller"
                ],
                "operationId": "cancelSubscription_2",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "WechatPayRedirectToAndroidApp": {
                "type": "object",
                "properties": {
                    "timestamp": {
                        "type": "string"
                    },
                    "experts": {
                        "uniqueItems": true,
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "package": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Annotation:

@Openapi(
  additionalProperties: AdditionalProperties(
    pubName: 'my_service',
  ),
  alwaysRun: true,
  inputSpecFile: 'lib/src/common/openapi_specs/my_service.json',
  generatorName: Generator.dart,
  outputDirectory: '../generated/my_service/',
)
class MyServiceOpenapiGeneratorConfig {}

Expected behavior

The parsing is done as a List and converted to a Set afterwards.

Logs

No response

Screenshots

No response

Platform

macOS

Library version

4.12.0

Flutter version

3.13.4

Flutter channel

stable

Additional context

No response