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

Closed
ricardoboss opened this issue Mar 2, 2024 · 2 comments
Closed

Invalid model generated via List in additional properties #137

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

Comments

@ricardoboss
Copy link
Contributor

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
@gibahjoe
Copy link
Owner

gibahjoe commented Nov 4, 2024

Hi, This seems to be an issue with the official openapi generator. I am able to reproduce it even with the latest official version released. You will have better luck raising the issue there. Please reopen this issue if you disagree.

@gibahjoe gibahjoe closed this as completed Nov 4, 2024
@ricardoboss
Copy link
Contributor Author

Yeah I guess they are tracking that issue with this one OpenAPITools/openapi-generator#8179

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

2 participants