-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[LagomScala] Add Scala API generator for lagomframework #6900 #6901
Conversation
import java.io.File; | ||
import java.util.*; | ||
|
||
public abstract class AbstractScalaLagomCodegen extends DefaultCodegen { |
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.
@gmkumar2005 Instead of creating another abstract class, what about using AbstractScalaCodegen.java instead?
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.
Done
|
||
import java.util.*; | ||
|
||
public class LagomScalaApiCodegen extends AbstractScalaLagomCodegen implements CodegenConfig { |
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 would suggest naming it as "ScalaLagomServerCodegen" following the naming convention of other server generator.
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.
Done
|
||
@Override | ||
public CodegenType getTag() { | ||
return CodegenType.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.
Please use CodegenType.SERVER
instead.
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.
Done
|
||
@Override | ||
public String getName() { | ||
return "lagomScalaApi"; |
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 would suggest scala-lagom
to follow the naming convention "{language}-{lagom}"
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.
Changed to scala-lagomApi to be able to distinguish from impl.
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 don't understand that part about distinguish from impl
, can you clarify?
@@ -81,3 +81,4 @@ io.swagger.codegen.languages.TypeScriptJqueryClientCodegen | |||
io.swagger.codegen.languages.TypeScriptNodeClientCodegen | |||
io.swagger.codegen.languages.UndertowCodegen | |||
io.swagger.codegen.languages.ZendExpressivePathHandlerServerCodegen | |||
io.swagger.codegen.languages.LagomScalaApiCodegen |
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.
Better to put it according to alpabetical order
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.
Done
@@ -0,0 +1,10 @@ | |||
// | |||
// Copyright (C) 2016 Lightbend Inc. <https://www.lightbend.com> |
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.
Can we remove it? The autogenerated files are unlicensed by default.
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.
Done
We can have another PR later to improve the code format. Ref: Scala style guide - http://docs.scala-lang.org/style/ |
|
||
@Override | ||
public String getHelp() { | ||
return "Generates a Lagom API in scala"; |
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.
FYI. I'll add the word "beta" later to help manage user expectation similar to what we've done for other new generators.
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.
Ok
…ved licensing info from generated code
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 won't have time to evaluate in depth for a few days.
At first glance, I only had one comment.
Although, I'm not familiar with Lagom… and the method signatures missing input parameters was weird to me. I'll have to run locally and see if the structure is just how Lagom does things. When I looked at it (I think pre-1.0 when it was only Java), it had a lot of abstractions even in Java.
public String toVarName(String name) { | ||
// sanitize name | ||
name = sanitizeName( | ||
name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. |
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 looks like a copy/paste. Can it be updated/fixed here, or does that affect something elsewhere?
String modifiedName = name;
Then, use modifiedName
within the method?
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.
Jim, you are right it is a copy paste from ScalaClientCodegen.Java. I guess this is needed for scala variables. Not sure what will break. Hence retained the logic.
With reference to method signatures.
Please have a look at https://github.com/lagom/sbt-lagom-descriptor-generator
The method signature generated by this PR matches with the one generated in above project.
Please let me know if you find any gaps.
I ran
|
UPDATE: I did another test and no longer encountered those errors. |
|
||
@Override | ||
public String getName() { | ||
return "scala-lagomApi"; |
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'll change this to scala-lagom
to conform to our naming convention.
|
||
@Override | ||
public String getHelp() { | ||
return "Generates a Lagom API in scala"; |
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'll add the word "beta" to the description.
@gmkumar2005 I've merged #7011 (enhancements, etc) into master. Please pull the latest master and let me know if you've any question. |
@wing328 lagom is a framework that supports generating both servers and clients. I see in that PR that you changed the generator to |
@jimschubert sure. I'll rename it to |
@jimschubert done via #7014 |
@gmkumar2005 when you've time, please reach me at my email address listed on my Github profile. Thanks. |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.2.3.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
This change will support code generation of Lagom Scala API. Lagom Scala Api project can be used for writing an implementation or as a client to consume an external service.
####Features which are not supported