openapi-generator
openapi-generator copied to clipboard
Fixed scala-sttp generator
Fixed multiple bugs present in the scala-sttp generator:
- The generated requests were using
Nothing
instead ofAny
as the capability parameter (as mentioned also here). Fixed by changing (api.mustache) to useAny
. - When the
responses
inside a swagger file were specified asdefault
, the code generated was erroneous. In particular, the returned value used to be generated asasJson[Unit]
which caused a matching error at runtime. Fixed by updating the return value toasEither(asString, ignore)
and the corresponding return type of the generated function as indicated by the sttp contributors here. -
3bc4895 fixes imported libraries in the generated
api
package. Libraries such asSet
used to be imported asorg.openapitools.client.model.Set
, howeverSet
was not generated as a model. Now it imports the Scala standard libraryscala.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:
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./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./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 thanks for the PR.
cc @clasnake (2017/07), @jimschubert (2017/09) ❤️, @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04)
@chrisbartoloburlo can you please resolve the merge conflicts when you've time?
@bgong-mdsol does this PR look good to you?
Can you please share some spec that can help reproduce the issue mentioned in the PR description?
Hi, This PR is quite helpful for us in sttp Is there anything I can do to help merge it ?
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?
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?
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
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.
Is there any update when this fix will be merged?
@wing328 This PR is quite helpful for us in scala-sttp project, can someone help to merge into OpenAPITools:master?
@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.
@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
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] ------------------------------------------------------------------------
Great, thank you all for your time and effort to get this merged. Much appreciated, James.