swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.03k forks source link

Swagger Codegen Kotlin - Transform Array by List in Model #8981

Open herveDarritchon opened 5 years ago

herveDarritchon commented 5 years ago

This issue aim is to open a dialog with you. I'd like to propose an evolution in the Kotlin template.

Currently, all the array in the Swagger Spec are transformed to kotlin.Array.

I propose to change that, so to transform array to List collections instead. I think, as in Java, it's better to handle List than Array.

What do you think about that ? Do you think it's a bad idea. Before proposing the pull request, I prefer asking the community.

Thanks

jnorthrup commented 5 years ago

I'd go with Array to limit the responsibility of the wire protocol generator defaults, and move the debate to command-line options for List, Sequence, etc.

herveDarritchon commented 5 years ago

ok, that sounds fair. Do you think we can go this way ?

jnorthrup commented 5 years ago

@herveDarritchon https://github.com/jnorthrup/XChange/blob/3aa6eacb335925248e1a78a4f6dac35b7976190d/xchange-idex/pom.xml#L71

does this help minimize the impact you are experiencing?

jnorthrup commented 5 years ago

in kotlin, List and MutableList are not identical, and sometimes the null-free nanny stuff will put a hard compilation error in places during migration.

also, with an Array, though potentially mutable, you have slightly better thread safety assumptions, where it takes a lot more effort to get a concurrency violation. my $.02 -- the cmdline switch or maven config is hopefully well positioned to mitigate the constraints on your models

Mehly commented 5 years ago

Android Studio even warns when using kotlin.Array in data classes:

image

When using kotlin.List the warning goes away.

jnorthrup commented 5 years ago

<typeMappings><typeMapping>array=kotlin.List</typeMapping></typeMappings> is the solution for android studio users to be sure.