Skip to content
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-server] --library=ktor (barebones implementation) #7412

Merged
merged 14 commits into from
Jan 27, 2018

Conversation

jimschubert
Copy link
Contributor

@jimschubert jimschubert commented Jan 15, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

This is the starter for Kotlin server generation. Initial library support is ktor.

Opening the PR for feedback and any assistance on fleshing this out is welcome.

See #6147

The -r option passed to sed is a GNU sed option for extended regex
evaluation. The -E option evaluates the same option, and is part of the
POSIX standard, meaning this option is available in GNU sed as well as
Apple's BSD variant.

This commit removes the need for users to install gnu-sed on Mac.
This adds a very barebones implementation for a ktor server generator.

This supports metrics and typed locations. All endpoins are stubbed to
return HTTP/1.1 501 Not Implemented.
Options available:

* featureAutoHead
* featureConditionalHeaders
* featureHSTS
* featureCORS
* featureCompression
ktor doesn't seem to explicitly accept oauth flow properties in its
configuration object. This may be a blocker for 'implicit' flow
definitions.
@jimschubert
Copy link
Contributor Author

jimschubert commented Jan 20, 2018

The generator still needs tests, but this adds a basic ktor generator.

There are still a couple of issues that still need to be worked out.

  • locations will require all HTTP verbs for a given path to be nested in the same location block. In separate blocks, it results in an exception when authentication is installed in the pipeline (it's seen as a duplicate feature)
  • Any route with a body parameter needs to have a vendor extension added so the route can be defined differently. typed location endpoints only support query parameters.

ktor locations are only supported for routes with path/query parameters.
Routes with body or file parameters must be declared with traditional
route api.

This commit also includes lambdas for simplifying processing in
library-based server generator code. As an example, ktor requires
lowercase http methods while spring (a potential future generator)
would require an uppercase such as HttpMethod.GET. It doesn't make sense
to modify these in the operations post-process method because that
format wouldn't be universally desirable.

The lambdas included in the KotlinServerCodegen:
* lowercase: converts all text to lowercase
* uppercase: converts all text to UPPERCASE
* titlecase: converts words (with configurable delim) to Title Case
* indented|indented_8|indented_12|indented_16: these helpers apply the
  same desired indent to all lines of an included fragment's text.
@jimschubert
Copy link
Contributor Author

jimschubert commented Jan 22, 2018

The last commit also includes lambdas for simplifying processing in
library-based server generator code. As an example, ktor requires
lowercase http methods while spring (a potential future generator)
would require an uppercase such as HttpMethod.GET. It doesn't make sense
to modify these in the operations post-process method because that
format wouldn't be universally desirable.

The lambdas included in the KotlinServerCodegen:

  • lowercase: converts all text to lowercase
  • uppercase: converts all text to UPPERCASE
  • titlecase: converts words (with configurable delim) to Title Case
  • indented|indented_8|indented_12|indented_16: these helpers apply the
    same desired indent to all lines of an included fragment's text.

* master: (133 commits)
  add a link to ebook (polish version)
  Add R namespace file (swagger-api#7467)
  Add Spring Petstore samples (async, java8-localdatetime) to CircleCI (swagger-api#7468)
  Revised core team members
  Ada code generator corrected: "=>" instead of "->". Fixes swagger-api#7450 (swagger-api#7456)
  Fixes issue swagger-api#7177 (SpringCodeGen dateLibrary "java8-localdatetime" option is ignored). (swagger-api#7178)
  Issue-7438 Fix that prevents generating interfaces when interfaceOnly is false. (swagger-api#7439)
  swagger-api#7093 - Add maven wrapper (swagger-api#7356)
  [csharp] Support arrays of arrays for properties and models (swagger-api#7400)
  [csharp] Fix ToJson to work with composition and polymorphism (swagger-api#7399)
  [csharp] Reference this.Configuration in client api template (swagger-api#7394)
  [JAX-RS][Spec] Removes throws Exception. (swagger-api#7437)
  Use supportsES6 flag in ts compilation for language typescript-angular (swagger-api#7408)
  Fix 7457: [Ada] wrong order for generated structures in *-models.ads (swagger-api#7462)
  Fix 7459: [Ada] wrong JSON in POST operations (swagger-api#7460)
  [erlang-client] Erlang request utils (swagger-api#7257)
  reenable pushing snapshot to maven repo
  Create CODE_OF_CONDUCT.md
  comment out update to docker image
  deleted unnecessary notes (swagger-api#7454)
  ...
@wing328 wing328 closed this Jan 24, 2018
@wing328 wing328 reopened this Jan 24, 2018
@wing328 wing328 added this to the v2.4.0 milestone Jan 24, 2018
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate --artifact-id "kotlin-petstore-server" -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l kotlin --library=ktor -o samples\server\petstore\kotlin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: -l kotlin => -l kotlin-server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. thanks for catching that. I've made the change.

Change `kotlin` to `kotlin-server`
@wing328
Copy link
Contributor

wing328 commented Jan 25, 2018

AppVeyor reports the following errors:

[00:02:41] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar (attach-javadocs) on project swagger-codegen: MavenReportException: Error while generating Javadoc:
[00:02:41] [ERROR] Exit code: 1 - C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\InlineModelResolver.java:437: warning: no description for @return
[00:02:41] [ERROR] * @return
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\languages\ScalaGatlingCodegen.java:199: warning: no description for @param
[00:02:41] [ERROR] * @param swagger
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\languages\StaticHtmlGenerator.java:80: warning - Tag @link: can't find processCompiler(Compiler) in io.swagger.codegen.languages.StaticHtmlGenerator
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\languages\ZendExpressivePathHandlerServerCodegen.java:136: warning: no description for @param
[00:02:41] [ERROR] * @param swagger
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\mustache\IndentedLambda.java:23: error: bad use of '>'
[00:02:41] [ERROR] *     {{#indent4}}{{>template}}{{/indent4}}
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\mustache\IndentedLambda.java:24: error: bad use of '>'
[00:02:41] [ERROR] *         {{#indent8}}{{>other_template}}{{/indent8}}
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] C:\projects\swagger-codegen-wh2wu\modules\swagger-codegen\src\main\java\io\swagger\codegen\mustache\TitlecaseLambda.java:39: warning: no description for @param
[00:02:41] [ERROR] * @param delimiter
[00:02:41] [ERROR] ^
[00:02:41] [ERROR] 

Please take a look when you've time.

@jimschubert
Copy link
Contributor Author

I noticed some errors there, but don't get them locally. Should I fix only the files in this PR or all files listed? I don't get if I changed something that has a negative impact on those unrelated files?

@wing328
Copy link
Contributor

wing328 commented Jan 25, 2018

Are you using JDK7 locally (which may explain why you didn't get the error in your local build)?

@jimschubert
Copy link
Contributor Author

Ah, no I'm not. I've been using JDK 8 since I got my new machine a few weeks ago. I didn't bother messing around with JDK 7 :]

…codegen into ktor-server-initial

* 'ktor-server-initial' of github.com:jimschubert/swagger-codegen:
  Update kotlin-server-petstore.bat
@jimschubert
Copy link
Contributor Author

Looks like AppVeyor is failing on Java 8, not Java 7:

C:\Progra~1\Java\jdk1.8.0\jre\..\bin\javadoc.exe -J-Xmx1024m @options @packages

I'm still confused how other PRs are green with the same errors. For example, another PR currently open has the same missing param description for swagger in ScalaGatlingCodegen.java, but that PR's AppVeyor build is all green. nbd, just weird that it would fail on this PR and not the other.

I've made those changes locally and run the javadocs:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] swagger-codegen-project ............................ SUCCESS [ 12.589 s]
[INFO] swagger-codegen (core library) ..................... SUCCESS [  0.773 s]
[INFO] swagger-codegen (executable) ....................... SUCCESS [  0.835 s]
[INFO] swagger-codegen (maven-plugin) ..................... SUCCESS [  1.383 s]
[INFO] swagger-generator .................................. SUCCESS [  0.313 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.341 s
[INFO] Finished at: 2018-01-25T13:10:38-05:00
[INFO] Final Memory: 34M/478M
[INFO] ------------------------------------------------------------------------

@wing328 wing328 merged commit 7cad47d into swagger-api:master Jan 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants