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

Invalid model generated via List in additional properties #137

Open
ricardoboss opened this issue Mar 2, 2024 · 0 comments
Open

Invalid model generated via List in additional properties #137

ricardoboss opened this issue Mar 2, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ricardoboss
Copy link

ricardoboss commented Mar 2, 2024

Description of the bug

When using a spec that defines a schema of an object containing string keys and string array values the generator produces invalid Dart code.

Steps to reproduce

To reproduce, create a new flutter project and set up openapi_generator with the following spec:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Test API",
    "version": "1.0"
  },
  "paths": {
    "/Test": {
      "get": {
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestDto"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TestDto": {
        "required": [
          "values"
        ],
        "type": "object",
        "properties": {
          "values": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "additionalProperties": false
      }
    }
  }
}

Expected behavior

The generated code should be able to compile.

The code should have the following differences:

        return TestDto(
          values: json[r'values'] == null
              ? const {}
-             : mapCastOfType<String, List>(json, r'values'),
+             : mapCastOfType<String, List<String>>(json, r'values') ?? {},
        );

Logs

No response

Screenshots

image

Platform

macOS

Library version

5.0.2

Flutter version

3.16.9

Flutter channel

stable

Additional context

No response

@ricardoboss ricardoboss added the bug Something isn't working label Mar 2, 2024
@ricardoboss ricardoboss changed the title Invalid model generated via additional properties Invalid model generated via List in additional properties Mar 2, 2024
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