-
Notifications
You must be signed in to change notification settings - Fork 424
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
Kotlin generator migration #26
Conversation
…rs String helpers instead
Thanks, @tcslater! @jimschubert - do you have time to help us review this PR? |
This looks good. Thank you! I have checked all the points of my migration guide: Here my review points:
Can you have a look at it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have started to remove the guava dependency. See #5.
|
||
// This is here to potentially warn the user when an option is not supoprted by the target framework. | ||
private Map<String, List<String>> optionsSupportedPerFramework = new ImmutableMap.Builder<String, List<String>>() | ||
.put(Constants.KTOR, Arrays.asList( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Collections.singletonMap(Constants.KTOR, Arrays.asList(..));
instead of guava.
Nice! Thank you for the update. By reviewing your code, I have noticed, tha you are using I think you should do it too.
|
An other point: When I have tried to generate the
I needed to add:
Maybe you could set the default library (when noting is set). I am not using the CLI, I use the |
Thanks. I have removed the guava dependency and fixed the default library option. |
* @return sanitized string | ||
*/ | ||
private String sanitizeKotlinSpecificNames(final String name) { | ||
String word = removeNonNameElementToCamelCase(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might cause problems. Whatever removeNonNameElementToCamelCase
does, if it changes name
at all, it may make enums stop working.
For instance, if an enum is last-call
, this method previously would have converted this to last_call
. If removeNonNameElementToCamelCase
changes name
to lastCall
or lastcall
, that expectation won't be met. I couldn't find the implementation of removeNonNameElementToCamelCase
, so I can't say for certain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was to fix an issue I was having where path parameters that were not in a valid kotlin format were not being converted for use as attributes in the generated data classes in Paths.kt. I'll look into it some more to make sure enums still work correctly.
} | ||
|
||
public String getName() { | ||
return "kotlin-client"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really part of this PR, but this seems as good a place as any to comment.
I think it's weird that this value is still used as an option to "language" when generating code. It makes sense that this generator's name is "kotlin-client" (more sense than when I generate scala client code at work using custom templates with -l scalatra
-- which is a server generator and not a language).
I had suggested in an issue in the swagger-codegen repo that there are multiple levels of generation that I think should be addressed:
- language (e.g. Kotlin)
- generator type (e.g. Client)
- framework (e.g. Default, OkHttp, Retrofit)
- Options: language version, framework version, etc.
To support a lot of this cleanly, you'd want shared templates that can be reused across framework options and across language/framework versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great comment, @jimschubert. This might help with another issue we're looking to solve with regard to versioning. @HugoMario can you track that please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree regarding duplication. All of the model templates for kotlin-client and kotlin-server are currently duplicated. These should be shared. I was going to try and refactor this but the only way I could think of getting it to work at the moment was to make the client generator a library option... so "-l kotlin --library=client" and "-l kotlin --library=ktor-server". This seemed a little weird so I opted not to pursue it in this PR
Sorry for the late response. Being from a repository I don't watch, this was sorted into a mail folder I hardly ever look at. |
@jimschubert:
I totally share this vision! Redundancy in templates: I have discovered this issue: swagger-api/swagger-codegen#4937 => not so much activity there. Generator names: For the moment |
@jimschubert thanks for the review, no worries about the delay. If you don't think it's too much overload, maybe star this repo now. In the long run, the goal is to move all generators here. |
…meters as described in open-api definition
Fixed Ktor Path template to generate nullable value for optional para…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #40 I have proposed to avoid fields declaration that hides fields or variables of a parent class. It would be nice if you could adopt this convention for kotlin.
- declare the
LOGGER
asprivate static
in your 3 classes - do not redeclare
enumPropertyNaming
inKotlinClientCodegen
.
Thank you in advance.
|
||
public static final String DATE_LIBRARY = "dateLibrary"; | ||
protected CodegenConstants.ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.camelCase; | ||
static Logger LOGGER = LoggerFactory.getLogger(KotlinClientCodegen.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOGGER
declaration should be private static
public class KotlinClientCodegen extends AbstractKotlinCodegen { | ||
|
||
public static final String DATE_LIBRARY = "dateLibrary"; | ||
protected CodegenConstants.ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.camelCase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enumPropertyNaming
is already declared in AbstractKotlinCodegen
. You just need to change the value (in the constructor for example) in the child class.
import java.util.Map; | ||
|
||
public abstract class AbstractKotlinCodegen extends DefaultCodegenConfig { | ||
static Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOGGER
declaration should be private static
public static final String DEFAULT_LIBRARY = Constants.KTOR; | ||
public static final String GENERATE_APIS = "generateApis"; | ||
|
||
static Logger LOGGER = LoggerFactory.getLogger(KotlinServerCodegen.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOGGER
declaration should be private static
Is there something to do here? I think this could be merged. |
Nothing more to be done that I'm aware of. I'd be happy for it to be merged. |
thanks a lot @tcslater !!! |
Migration of kotlin generator files from swagger-codegen.
Updated for compatability with 3.0 changes and template migration from mustache to handlebars as per https://github.com/swagger-api/swagger-codegen/wiki/Swagger-Codegen-migration-from-Mustache-and-Handlebars-templates
Related PR for cleanup in swaggen-codegen 3.0.0 swagger-api/swagger-codegen#7739