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.85k stars 6.02k forks source link

Please add Ktor (Kotlin server) code generation #6147

Open kamyar1979 opened 7 years ago

kamyar1979 commented 7 years ago
Description

Please add Ktor http framework support for kotlin.

Swagger-codegen version

Swagger codegen 2.2.2

Suggest a fix/enhancement

Ktor is the most sophisticated Kotlin web framework. Please add support for it.

wing328 commented 7 years ago

@kamyar1979 thanks for the suggestion. Do you have time to help contribute the new generator?

I think a good starting point is to clone one of the Java server stub generators.

Ref: Ktor

cc @jimschubert

kamyar1979 commented 7 years ago

I will be happy and proud of contributing to your valuable project. How can I start?

wing328 commented 7 years ago

@kamyar1979 thank you. The overview section lists all the supported server stub generator. Which one are you most familiar with?

wing328 commented 7 years ago

Another way is to start the generator from scratch similar to what we've done for PowerShell and Rust. To begin with, please create Ktor with 3 endpoints listed below:

Then based on the Ktor code, we'll start the reverse engineering process to create the generator and templates.

kamyar1979 commented 7 years ago

Ok I will start tonight! It is my work hours now! Thanks for help!

wing328 commented 7 years ago

No problem. Let us know if you need any help.

jimschubert commented 7 years ago

When I created the Kotlin client generator, I added a new.sh script to help get the right files in place for a new generator.

./new.sh -stn Ktor

This command should generate the files for a server generator, including empty test files.

kamyar1979 commented 7 years ago

@jimschubert Your shell script failed with 'sed' error!

sed: illegal option -- r

Edit: Fixed with installing gnu sed (gsed)) on mac and changing all sed to gsed in script

kamyar1979 commented 7 years ago

Can I write my extension in Kotlin instead of java?

wing328 commented 7 years ago

@kamyar1979 not at the moment as the project is based on Java.

If you don't want to code in Java, what about creating Ktor Petstore as suggested in https://github.com/swagger-api/swagger-codegen/issues/6147#issuecomment-317237440 and then we'll do the reverse engineering to create the generator and templates?

jimschubert commented 7 years ago

@kamyar1979 I may need to set up some checks in the script prior to execution. gsed would require a check for Darwin vs Linux in the script, while missing sed on a Mac could just fail with a requirement to install gnu core utils or gnu-sed (which is what I have installed).

You could move shared Kotlin code to an abstract base class in the same way as the C# and ASP.NET Core generators. I don't know that directly extending the client generator would work for for a server generator, although I don't think I've ever tried it.

kamyar1979 commented 7 years ago

I am doing the job of adding Ktor. Lets add Kotlin polymorphism support by creating AbstractKotlinCodegen

kamyar1979 commented 7 years ago

BTW, I am also a Haskeller! Lets add AbstractHaskellCodegen and then add ScottyServerCodegen

wing328 commented 7 years ago

I'll create a separate task to track the Scotty generator

kamyar1979 commented 7 years ago

Sure! It is certainly better! And I just started by Kotlin! After completing it and merging, I will start Scotty! Thanks!

mykola-dev commented 6 years ago

are there any news on ktor support?

wing328 commented 6 years ago

@deviant-studio I think @kamyar1979 is probably too busy with other tasks. Do you have time to contribute the generator? A good starting point is https://github.com/swagger-api/swagger-codegen/issues/6147#issuecomment-317237440

jimschubert commented 6 years ago

I'll try to take a stab at this over the next few weeks.

jimschubert commented 6 years ago

See #7412. It's a very barebones implementation of the server generator.

wing328 commented 6 years ago

@kamyar1979 @deviant-studio the PR by @jimschubert has been merged into master. Please pull the latest master or use the SNAPSHOT version to give it a try.

Tweet to promote the new generator: https://twitter.com/wing328/status/957190593574199296

florianhof commented 6 years ago

Concerning the new kotlin-server codegen but a bit off-topic (sorry) ... For enums, could a toString be added that returns the custom value? It would make it friendly for the Jackson deserializer/serializer. It's also what Swagger use to lists the possible values of an enum. More in my big comment in #7811.

jimschubert commented 6 years ago

I responded to your linked comment.