Skip to content

Enhance scalatra server codegen to include openapi info and package dir#11385

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
ravinallappan:master
Feb 27, 2022
Merged

Enhance scalatra server codegen to include openapi info and package dir#11385
wing328 merged 3 commits intoOpenAPITools:masterfrom
ravinallappan:master

Conversation

@ravinallappan
Copy link
Contributor

@wing328 @jimschubert @jmini

Enhanced scalatra server codegen to include followings:

  1. Added following fields to pickup values from openapi spec :
  • apiVersion (SevletApp.mustache) - new
  • appName (SevletApp.mustache) - existing but was hardcoded
  • appDescription (SevletApp.mustache) - existing but was hardcoded
  • infoUrl (SevletApp.mustache) - existing but was hardcoded
  • infoEmail (SevletApp.mustache) - existing but was hardcoded
  • licenseInfo (SevletApp.mustache) - existing but was hardcoded
  • licenseUrl (SevletApp.mustache) - existing but was hardcoded
  1. Update build.sbt to pick up values from openapi spec.
  2. Bootstrap and JettyMain to generate codes within invoker package

PR checklist

  • [ X] Read the contribution guidelines.
  • [ X] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [ X] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • [X ] File the PR against the correct branch: master (5.3.0), 6.0.x
  • [X ] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Jan 24, 2022

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@ravinallappan
Copy link
Contributor Author

ravinallappan commented Jan 24, 2022

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

Thanks. Updated accordingly.

@ravinallappan
Copy link
Contributor Author

Any action pending on me on this PR?

@wing328
Copy link
Member

wing328 commented Feb 14, 2022

cc @clasnake (2017/07), @jimschubert (2017/09) ❤️, @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04)

@wing328 wing328 added this to the 6.0.0 milestone Feb 14, 2022
@wing328 wing328 changed the title enhance scalatra server codegen to include openapi info and package dir Enhance scalatra server codegen to include openapi info and package dir Feb 14, 2022
@wing328
Copy link
Member

wing328 commented Feb 14, 2022

I ran ./bin/generate-samples.sh ./bin/configs/other/scalatra.yaml to update the samples but then I got the following when running sbt test:

[info] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.4. Compiling...
[info]   Compilation completed in 15.665s.
[error] /Users/williamcheng/Code/openapi-generator2/samples/server/petstore/scalatra/src/main/scala/org/openapitools/app/ServletApp.scala:19:7: ResourcesApp is already defined as class ResourcesApp
[error] class ResourcesApp(implicit protected val swagger: OpenAPIApp)
[error]       ^
[error] /Users/williamcheng/Code/openapi-generator2/samples/server/petstore/scalatra/src/main/scala/org/openapitools/app/ServletApp.scala:26:7: OpenAPIApp is already defined as class OpenAPIApp
[error] class OpenAPIApp extends Swagger(apiInfo = OpenAPIInfo.apiInfo, apiVersion = "1.0.0", swaggerVersion = Swagger.SpecVersion)
[error]       ^
[error] /Users/williamcheng/Code/openapi-generator2/samples/server/petstore/scalatra/src/main/scala/org/openapitools/app/ServletApp.scala:28:8: OpenAPIInfo is already defined as object OpenAPIInfo
[error] object OpenAPIInfo {
[error]        ^
[error] three errors found
[error] (Compile / compileIncremental) Compilation failed

Can you please take a look when you've time?

@ravinallappan
Copy link
Contributor Author

I able to see the same error. However after I removed the project and regenerate the code - i able to run sbt test without error.

ravi@ravi-desktop:~/github/openapi-generator$ rm -rf samples/server/petstore/scalatra

ravi@ravi-desktop:~/github/openapi-generator$ ./bin/generate-samples.sh ./bin/configs/other/scalatra.yaml
# START SCRIPT: ./bin/generate-samples.sh
This script generates all configs under bin/configs by default.
You may generate a targeted script or set of scripts using glob patterns.

For example:
    ./bin/generate-samples.sh bin/configs/java-*

You may generate a single config with additional options if you use -- to
separate the single config file from the generator arguments.

For example:
    ./bin/generate-samples.sh bin/configs/java-vertx.yaml -- --global-property debugModels=true


[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (samples/server/petstore/scalatra) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: scalatra (server)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'scalatra' is considered stable.
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
...

ravi@ravi-desktop:~/github/openapi-generator$ cd samples/server/petstore/scalatra

ravi@ravi-desktop:~/github/openapi-generator/samples/server/petstore/scalatra$ sbt test
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /home/ravi/github/openapi-generator/samples/server/petstore/scalatra/project
[info] Updating ProjectRef(uri("file:/home/ravi/github/openapi-generator/samples/server/petstore/scalatra/project/"), "scalatra-build")...
[info] Done updating.
[info] Loading settings from build.sbt ...
[info] Set current project to org.openapitools-openapi-server (in build file:/home/ravi/github/openapi-generator/samples/server/petstore/scalatra/)
[info] Updating ...
[info] Done updating.
[info] Formatting 12 Scala sources ProjectRef(uri("file:/home/ravi/github/openapi-generator/samples/server/petstore/scalatra/"), "scalatra")(compile) ...
[info] Reformatted 10 Scala sources ProjectRef(uri("file:/home/ravi/github/openapi-generator/samples/server/petstore/scalatra/"), "scalatra")(compile).
[info] Compiling 12 Scala sources to /home/ravi/github/openapi-generator/samples/server/petstore/scalatra/target/scala-2.12/classes ...
[info] Done compiling.
[info] Run completed in 19 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 4 s, completed Feb 17, 2022 11:28:01 AM
ravi@ravi-desktop:~/github/openapi-generator/samples/server/petstore/scalatra$ 

Seems like those are left over from previous code's generation.

@wing328
Copy link
Member

wing328 commented Feb 27, 2022

Confirmed it's good now. Thanks for the hint.

@wing328 wing328 merged commit a1da4c9 into OpenAPITools:master Feb 27, 2022
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