You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ openapi-generator-cli generate \
-i widget-api.yml \
-g scala-sttp \
--additional-properties=jsonLibrary=circe,mainPackage=com.acme.widgets
[main] WARN o.o.codegen.DefaultCodegen - OpenAPI 3.1 support is still in beta. To report an issue related to 3.1 spec, please kindly open an issue in the Github repo: https://github.com/openAPITools/openapi-generator.
[main] INFO o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: scala-sttp (client)
[main] INFO o.o.codegen.DefaultGenerator - Generator 'scala-sttp' is considered stable.
[main] INFO o.o.c.languages.AbstractScalaCodegen - Environment variable SCALA_POST_PROCESS_FILE not defined so the Scala code may not be properly formatted. To define it, try 'export SCALA_POST_PROCESS_FILE=/usr/local/bin/scalafmt' (Linux/Mac)
[main] INFO o.o.c.languages.AbstractScalaCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN o.o.codegen.DefaultCodegen - OpenAPI 3.1 support is still in beta. To report an issue related to 3.1 spec, please kindly open an issue in the Github repo: https://github.com/openAPITools/openapi-generator.
[main] INFO o.o.codegen.TemplateManager - writing file ./src/main/scala/com/acme/widgets/model/Widget.scala
[main] INFO o.o.codegen.TemplateManager - writing file ./src/main/scala/com/acme/widgets/api/DefaultApi.scala
[main] INFO o.o.codegen.TemplateManager - Ignored ./README.md (Ignored by rule in ignore file.)
[main] INFO o.o.codegen.TemplateManager - Ignored ./build.sbt (Ignored by rule in ignore file.)
[main] INFO o.o.codegen.TemplateManager - writing file ./src/main/scala/com/acme/widgets/core/JsonSupport.scala
[main] INFO o.o.codegen.TemplateManager - writing file ./src/main/scala/com/acme/widgets/core/AdditionalTypeSerializers.scala
[main] INFO o.o.codegen.TemplateManager - writing file ./project/build.properties
[main] INFO o.o.codegen.TemplateManager - writing file ./src/main/scala/com/acme/widgets/core/DateSerializers.scala
[main] INFO o.o.codegen.TemplateManager - Skipped ./.openapi-generator-ignore (Skipped by supportingFiles options supplied by user.)
[main] INFO o.o.codegen.TemplateManager - writing file ./.openapi-generator/VERSION
[main] INFO o.o.codegen.TemplateManager - writing file ./.openapi-generator/FILES
################################################################################# Thanks for using OpenAPI Generator. ## Please consider donation to help us maintain this project 🙏 ## https://opencollective.com/openapi_generator/donate #################################################################################
Steps to reproduce
After generating the project, the initial build fails, since circe-generic (for auto-derivation) is not added to build.sbt (separate issue - it should probably be included, maybe with % Provided):
$ sbt compile
[info] compiling 5 Scala sources to <redacted>/target/scala-2.13/classes ...
[error] <redacted>/src/main/scala/com/acme/widgets/core/JsonSupport.scala:16:17: object generic is not a member of package io.circe
[error] import io.circe.generic.AutoDerivation
[error] ^
[error] <redacted>/src/main/scala/com/acme/widgets/core/JsonSupport.scala:19:46: not found: type AutoDerivation
[error] object JsonSupport extends SttpCirceApi with AutoDerivation with DateSerializers with AdditionalTypeSerializers {
[error] ^
[error] <redacted>/src/main/scala/com/acme/widgets/api/DefaultApi.scala:38:23: could not find implicit value for evidence parameter of type io.circe.Decoder[com.acme.widgets.model.Widget]
[error] .response(asJson[Widget])
[error] ^
[error] three errors found
[error] (Compile / compileIncremental) Compilation failed
After adding "io.circe" %% "circe-generic" % "0.14.1" to build.sbt, compilation fails again:
$ sbt compile
[info] welcome to sbt 1.6.1 (Ubuntu Java 17.0.14)
[info] loading global plugins from <redacted>/.sbt/1.0/plugins
[info] loading project definition from <redacted>/project
[info] loading settings for project scala-sttp-client from build.sbt ...
[info] set current project to openapi-client (in build file:<redacted>/)
[info] Executing in batch mode. For better performance use sbt's shell[info] compiling 1 Scala source to <redacted>/target/scala-2.13/classes ...[info] compiling 1 Scala source to <redacted>/target/scala-2.13/classes ...[error] <redacted>/src/main/scala/com/acme/widgets/api/DefaultApi.scala:38:23: could not find implicit value for evidence parameter of type io.circe.Decoder[com.acme.widgets.model.Widget][error] .response(asJson[Widget])[error] ^[error] one error found[error] (Compile / compileIncremental) Compilation failed[error] Total time: 4 s, completed Apr 3, 2025, 3:01:20 PM
For enumerations defined as standalone models, decoder/encoder are generated in core.JsonSupport. These are not generated for enumerations defined inline.
Related issues/PRs
There is already a similar PR for the json4s implementation:
I'm hoping to submit a pull request shortly to address this. The missing encoder and decoder can be added to modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
JSON encoder and decoder are not generated for an enumeration if it is defined "inline", rather than as a component.
openapi-generator version
OpenAPI declaration file content or url
widget-api.yml
Generation Details
Steps to reproduce
After generating the project, the initial build fails, since
circe-generic
(for auto-derivation) is not added tobuild.sbt
(separate issue - it should probably be included, maybe with% Provided
):After adding
"io.circe" %% "circe-generic" % "0.14.1"
tobuild.sbt
, compilation fails again:For enumerations defined as standalone models, decoder/encoder are generated in
core.JsonSupport
. These are not generated for enumerations defined inline.Related issues/PRs
There is already a similar PR for the
json4s
implementation:#17697
Suggest a fix
I'm hoping to submit a pull request shortly to address this. The missing encoder and decoder can be added to
modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache
.The text was updated successfully, but these errors were encountered: