Skip to content

[Dart] Bug generating Models, toJson and fromJson methods can have incorrect keys #9631

@nickmeinhold

Description

@nickmeinhold
Description

It seems that, as described in #4898, the generated code only works with the protocol described in the API definition when the parameter mangling results in the same name as the original.

Eg, for an API definition that uses lowercase_with_underscores for parameter names, the generated fromJson method will use keys in lowerCamelCase and so return null. If you manually change the key to have the form lowercase_with_underscores it works.

Swagger-codegen version

2.4.7

Swagger declaration file content or url

http://timetableapi.ptv.vic.gov.au/swagger/docs/v3

Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://timetableapi.ptv.vic.gov.au/swagger/docs/v3 -l dart -o ../ptv_client_lib -DbrowserClient=false

Steps to reproduce

The PTV API requires a signature that is unique to each request so I had to modify the generated code, so making an API call with the library generated from the command line call above will just produce an error. I will try and find another API that illustrates the problem if that's helpful.

Related issues/PRs

I believe this issue is a part of #4898 and subsequent PR #5019. A more recent issue #9384 may also be related.

Suggest a fix/enhancement

As suggested in #5019, use of {{baseName}} (which is the original name of the parameter definition as parsed from the API definition) instead of {{paramName}} (which is the sanitized version of the parameter name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions