Skip to content
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

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

Open
zellidev0 opened this issue Nov 2, 2023 · 0 comments
Open

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

zellidev0 opened this issue Nov 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@zellidev0
Copy link

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

@zellidev0 zellidev0 added the bug Something isn't working label Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant