openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Fixed scala-sttp generator

Open chrisbartoloburlo opened this issue 2 years ago • 9 comments

Fixed multiple bugs present in the scala-sttp generator:

  1. The generated requests were using Nothing instead of Any as the capability parameter (as mentioned also here). Fixed by changing (api.mustache) to use Any.
  2. When the responses inside a swagger file were specified as default, the code generated was erroneous. In particular, the returned value used to be generated as asJson[Unit] which caused a matching error at runtime. Fixed by updating the return value to asEither(asString, ignore) and the corresponding return type of the generated function as indicated by the sttp contributors here.
  3. 3bc4895 fixes imported libraries in the generated api package. Libraries such as Set used to be imported as org.openapitools.client.model.Set, however Set was not generated as a model. Now it imports the Scala standard library scala.collection.immutable.Set instead.

https://github.com/OpenAPITools/openapi-generator/pull/11949#issuecomment-1082813214 I believe this schema.yaml.zip file reproduces all the errors mentioned above.

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. @chameleon82

chrisbartoloburlo avatar Mar 23 '22 15:03 chrisbartoloburlo

@chrisbartoloburlo thanks for the PR.

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

wing328 avatar Mar 24 '22 16:03 wing328

@chrisbartoloburlo can you please resolve the merge conflicts when you've time?

@bgong-mdsol does this PR look good to you?

wing328 avatar Mar 30 '22 08:03 wing328

Can you please share some spec that can help reproduce the issue mentioned in the PR description?

wing328 avatar Mar 30 '22 09:03 wing328

Hi, This PR is quite helpful for us in sttp Is there anything I can do to help merge it ?

Pask423 avatar May 19 '22 15:05 Pask423

3bc4895 fixes imported libraries in the generated api package. Libraries such as Set used to be imported as org.openapitools.client.model.Set, however Set was not generated as a model. Now it imports the Scala standard library scala.collection.immutable.Set instead.

I think I am having the same problem in Array. Can you also fix that?

jtjeferreira avatar May 30 '22 17:05 jtjeferreira

3bc4895 fixes imported libraries in the generated api package. Libraries such as Set used to be imported as org.openapitools.client.model.Set, however Set was not generated as a model. Now it imports the Scala standard library scala.collection.immutable.Set instead.

I think I am having the same problem in Array. Can you also fix that?

Of course! Can I first have some more information about the problem you are having?

chrisbartoloburlo avatar May 31 '22 08:05 chrisbartoloburlo

Of course! Can I first have some more information about the problem you are having?

Using version 6.0.0 I was seeing generated code like import org.openapitools.client.model.Array[Byte]

from a schema like this

"schema": {
  "type": "string",
  "format": "byte"
}

I suspect this is similar to what you did in 3bc4895

jtjeferreira avatar May 31 '22 18:05 jtjeferreira

Of course! Can I first have some more information about the problem you are having?

Using version 6.0.0 I was seeing generated code like import org.openapitools.client.model.Array[Byte]

from a schema like this

"schema": {
  "type": "string",
  "format": "byte"
}

I suspect this is similar to what you did in 3bc4895

I think this is a tad more involving than what I did in 3bc4895 and should be addressed in a separate PR. I would suggest opening an issue including a swagger file to reproduce the issue.

chrisbartoloburlo avatar Jun 01 '22 07:06 chrisbartoloburlo

Is there any update when this fix will be merged?

reddicj avatar Aug 05 '22 08:08 reddicj

@wing328 This PR is quite helpful for us in scala-sttp project, can someone help to merge into OpenAPITools:master?

bgong-mdsol avatar Aug 10 '22 11:08 bgong-mdsol

@bgong-mdsol thanks for reviewing this change. Is it correct to say that you've tested this PR locally and it works well with your spec?

I'm also try to run some tests this weekend.

wing328 avatar Aug 10 '22 12:08 wing328

@bgong-mdsol thanks for reviewing this change. Is it correct to say that you've tested this PR locally and it works well with your spec?

I'm also try to run some tests this weekend.

@wing328 yes, it works well with my spec. Thanks a lot @wing328 @chameleon82

bgong-mdsol avatar Aug 11 '22 13:08 bgong-mdsol

Tested locally and the result is good:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------< org.openapitools:scalaz-sttp-petstore-client >------------
[INFO] Building scala-sttp-petstore-client 1.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.5.0:exec (sbt-test) @ scalaz-sttp-petstore-client ---
[info] welcome to sbt 1.6.1 (Eclipse Adoptium Java 11.0.13)
[info] loading project definition from /Users/williamcheng/Code/openapi-generator5/samples/client/petstore/scala-sttp/project
[info] loading settings for project scala-sttp from build.sbt ...
[info] set current project to scala-sttp-petstore (in build file:/Users/williamcheng/Code/openapi-generator5/samples/client/petstore/scala-sttp/)
[info] compiling 15 Scala sources to /Users/williamcheng/Code/openapi-generator5/samples/client/petstore/scala-sttp/target/scala-2.13/classes ...
[warn] Getting the hostname WILLIAMs-MacBook-Pro.local was slow (5008.2173 ms). This is likely because the computer's hostname is not set. You can set the hostname with the command: scutil --set HostName "$(scutil --get LocalHostName).local".
[info] done compiling
[success] Total time: 12 s, completed 15 Aug 2022, 6:38:32 PM
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.367 s
[INFO] Finished at: 2022-08-15T18:38:32+08:00
[INFO] ------------------------------------------------------------------------


wing328 avatar Aug 15 '22 10:08 wing328

Great, thank you all for your time and effort to get this merged. Much appreciated, James.

reddicj avatar Aug 15 '22 10:08 reddicj