6 ms·
> I've found swagger codegen to be really, really inconsistent between different implementations. A few of them - I recall we had a team using Qt - didn't even
by wing328hk 10y ago
> I've found swagger codegen to be really, really inconsistent between different implementations. A few of them - I recall we had a team using Qt - didn't even generate compilable code. When I looked into the infrastructure of the codegen project, I found... mustache.
Yup, some generators (e.g. ActionScript, Qt5 C++) are less mature than the others (e.g. Ruby, PHP, C#). For the issues with Qt5 C++ generator, please open an issue via http://github.com/swagger-api/swagger-codegen/issues/new http://github.com/swagger-api/swagger-codegen/issues/new so that the community can help work on it.
> Mustache is fine for doing a little view rendering, but for language generation... it's really obnoxious to use. Say you want to customize the output. Well, now you're basically replacing one of those magic .mustache files. And what's the model you use to generate those mustache files? Well, you got to look through the codebase for that.
Instead looking through the codebase, you may also want to try the debug flag (e.g. debugOperations, debugModels) to get a list of tags available in the mustache templates: https://github.com/swagger-api/swagger-codegen/wiki/FAQ#how-to-debug-swagger-codegen https://github.com/swagger-api/swagger-codegen/wiki/FAQ#how-...
I agree that mustache may not be the best template system in the world but it's easy to learn and developers seem pretty comfortable using it.
> Especially if you do not use the JVM as part of your existing toolchain.
One can also use docker (https://github.com/swagger-api/swagger-codegen#docker https://github.com/swagger-api/swagger-codegen#docker) or https://generator.swagger.io https://generator.swagger.io (https://github.com/swagger-api/swagger-codegen#online-generators https://github.com/swagger-api/swagger-codegen#online-genera...) to leverage Swagger Codegen without installing JVM.
Thanks for the feedback and I hope the above helps.
(Disclosure: I'm a top contributor to the project)
- gregopet 10y agoMustache is the most limiting (not to mention ugly) template language I've seen in a long time. It allows no logic whatsoever and even writing simple if statements is tedious. We have a Swagger spec from which we generate Asciidoctor documentation via a Gradle plugin which works very nice, and generate basic POJOs for Java and POCOs for C#. That... does not work very well for our purposes. We wanted to produce named enumerables by using custom extensions and found no way of doing it with Mustache. It didn't help that our custom extension YAML was passed into Mustache as serialized JSON. One of our developers took it upon himself to make it work and ended up writing his own simple version of the Codegen which works well enough for us. He tried modifying one of the backends preparing data for Mustache but then said rewriting it on his own was just simpler.