Skip to content

Commit 4048942

Browse files
authored
[BUG] [scala-sttp] [circe] Generate circe encoder and decoder for inline enumeration (#21028)
* Generate circe encoder and decoder for inline enumeration * Add missing circe-generic dependency, and the corresponding circeVersion property. --------- Co-authored-by: Basil Mironenko <[email protected]>
1 parent 6bf5289 commit 4048942

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

docs/generators/scala-sttp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2020
| ------ | ----------- | ------ | ------- |
2121
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2222
|apiPackage|package for generated api classes| |null|
23+
|circeVersion|The version of circe library| |0.14.1|
2324
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for JDK 1.8+)</dd></dl>|java8|
2425
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
2526
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
4949
"joda-time library", "2.10.13");
5050
private static final StringProperty JSON4S_VERSION = new StringProperty("json4sVersion", "The version of json4s " +
5151
"library", "3.6.11");
52-
52+
private static final StringProperty CIRCE_VERSION = new StringProperty("circeVersion", "The version of circe " +
53+
"library", "0.14.1");
5354
private static final JsonLibraryProperty JSON_LIBRARY_PROPERTY = new JsonLibraryProperty();
5455

5556
public static final String DEFAULT_PACKAGE_NAME = "org.openapitools.client";
5657
private static final PackageProperty PACKAGE_PROPERTY = new PackageProperty();
5758

5859
private static final List<Property<?>> properties = Arrays.asList(
5960
STTP_CLIENT_VERSION, USE_SEPARATE_ERROR_CHANNEL, JODA_TIME_VERSION,
60-
JSON4S_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
61+
JSON4S_VERSION, CIRCE_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
6162

6263
private final Logger LOGGER = LoggerFactory.getLogger(ScalaSttpClientCodegen.class);
6364

modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ libraryDependencies ++= Seq(
1515
"org.json4s" %% "json4s-jackson" % "{{json4sVersion}}"
1616
{{/json4s}}
1717
{{#circe}}
18-
"com.softwaremill.sttp.client3" %% "circe" % "{{sttpClientVersion}}"
18+
"com.softwaremill.sttp.client3" %% "circe" % "{{sttpClientVersion}}",
19+
"io.circe" %% "circe-generic" % "{{circeVersion}}"
1920
{{/circe}}
2021
)
2122

modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ object JsonSupport extends SttpCirceApi with AutoDerivation with DateSerializers
5353
implicit val {{classname}}Decoder: Decoder[{{classname}}.{{classname}}] = Decoder.decodeEnumeration({{classname}})
5454
implicit val {{classname}}Encoder: Encoder[{{classname}}.{{classname}}] = Encoder.encodeEnumeration({{classname}})
5555
{{/isEnum}}
56+
{{#hasEnums}}
57+
{{#vars}}
58+
{{#isEnum}}
59+
implicit val {{classname}}{{datatypeWithEnum}}Decoder: Decoder[{{classname}}Enums.{{datatypeWithEnum}}] = Decoder.decodeEnumeration({{classname}}Enums.{{datatypeWithEnum}})
60+
implicit val {{classname}}{{datatypeWithEnum}}Encoder: Encoder[{{classname}}Enums.{{datatypeWithEnum}}] = Encoder.encodeEnumeration({{classname}}Enums.{{datatypeWithEnum}})
61+
{{/isEnum}}
62+
{{/vars}}
63+
{{/hasEnums}}
5664
{{/model}}
5765
{{/models}}
5866
}

0 commit comments

Comments
 (0)