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

[Scala][sttp] various bug fixes #12254

Merged
merged 4 commits into from
May 4, 2022
Merged

Conversation

smiklos
Copy link
Contributor

@smiklos smiklos commented Apr 27, 2022

There are a couple of issues with the sttp codegen support.

  1. enum should not be used as it will be a reserved keyword -> changed this in JsonSupport
  2. Enums were completely missed and not generated at all -> Fixed
  3. AnyType was added as value type for maps where the schema type is object. These should be encoded as a json library specific json value (personal opinion)
  4. URI serializer is added to support URI as well.

PR checklist

  • Read the contribution guidelines.
  • 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.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@smiklos
Copy link
Contributor Author

smiklos commented Apr 27, 2022

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

@smiklos
Copy link
Contributor Author

smiklos commented Apr 27, 2022

merge-swagger.yaml.gz
This is the schema I used , has plenty of enums.

The petstore example generates an enum but no Json4s or circe enums are generated at all. The deafult is json4s which would only fail runtime but circe doesn't even compile in this case.

@chameleon82
Copy link
Contributor

Hi @smiklos,
Thank you for the PR! Looks good to me.

@wing328 wing328 added this to the 6.0.0 milestone May 4, 2022
@wing328 wing328 changed the title Scala sttp fixes [Scala][sttp] various bug fixes May 4, 2022
@wing328 wing328 merged commit bee9c79 into OpenAPITools:master May 4, 2022
@wing328
Copy link
Member

wing328 commented Aug 20, 2022

@smiklos thanks again for the PR.

I've filed #13235 to fix a minor bug.

I tried the circe json library but the output doesn't compile:

[error] /private/tmp/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala:64:12: No implicit view available from Seq[org.openapitools.client.model.User] => sttp.client3.BasicRequestBody.
[error]       .body(user)
[error]            ^
[error] /private/tmp/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala:84:12: No implicit view available from Seq[org.openapitools.client.model.User] => sttp.client3.BasicRequestBody.
[error]       .body(user)
[error]            ^
[error] /private/tmp/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala:122:23: could not find implicit value for evidence parameter of type io.circe.Decoder[org.openapitools.client.model.User]
[error]       .response(asJson[User])
[error]                       ^
[error] /private/tmp/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala:181:12: No implicit view available from org.openapitools.client.model.User => sttp.client3.BasicRequestBody.
[error]       .body(user)
[error]            ^
[error] 18 errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 11 s, completed 20 Aug 2022, 2:42:49 PM

Does it work for you?

To repeat the issue, generate the code with:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g scala-sttp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/scala-sttp/ --additional-properties jsonLibrary=circe

and then run the following under `tmp/-scala-sttp/

sbt test

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.

None yet

3 participants