Skip to content

Commit b218e23

Browse files
authored
Improve handling of pekko versions in scala-akka-http-server generator (#20277)
* Fix issue 20275 Improve handling of pekko versions * Generated docs * Use version 1.1.0 as default version of pekko-http. * Updated sample
1 parent e7b5f34 commit b218e23

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

docs/generators/scala-akka-http-server.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3333
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
3434
|modelPackage|package for generated models| |null|
3535
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
36+
|pekkoHttpVersion|The version of pekko-http| |1.1.0|
3637
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
3738
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3839
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
4545
protected String akkaHttpVersion;
4646
protected boolean generateAsManagedSources;
4747
protected boolean useApachePekko;
48+
protected String pekkoHttpVersion;
4849

4950
public static final String AKKA_HTTP_VERSION = "akkaHttpVersion";
5051
public static final String AKKA_HTTP_VERSION_DESC = "The version of akka-http";
52+
public static final String PEKKO_HTTP_VERSION = "pekkoHttpVersion";
53+
public static final String PEKKO_HTTP_VERSION_DESC = "The version of pekko-http";
5154
public static final String DEFAULT_AKKA_HTTP_VERSION = "10.1.10";
52-
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.0.0";
55+
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.1.0";
5356

5457
public static final String GENERATE_AS_MANAGED_SOURCES = "asManagedSources";
5558
public static final String GENERATE_AS_MANAGED_SOURCES_DESC = "Resulting files cab be used as managed resources. No build files or default controllers will be generated";
@@ -124,6 +127,7 @@ public ScalaAkkaHttpServerCodegen() {
124127
akkaHttpVersion = DEFAULT_AKKA_HTTP_VERSION;
125128
generateAsManagedSources = DEFAULT_GENERATE_AS_MANAGED_SOURCES;
126129
useApachePekko = DEFAULT_USE_APACHE_PEKKO;
130+
pekkoHttpVersion = DEFAULT_PEKKO_HTTP_VERSION;
127131

128132
setReservedWordsLowerCase(
129133
Arrays.asList(
@@ -141,6 +145,7 @@ public ScalaAkkaHttpServerCodegen() {
141145
cliOptions.add(CliOption.newString(AKKA_HTTP_VERSION, AKKA_HTTP_VERSION_DESC).defaultValue(akkaHttpVersion));
142146
cliOptions.add(CliOption.newBoolean(GENERATE_AS_MANAGED_SOURCES, GENERATE_AS_MANAGED_SOURCES_DESC).defaultValue(Boolean.valueOf(DEFAULT_GENERATE_AS_MANAGED_SOURCES).toString()));
143147
cliOptions.add(CliOption.newBoolean(USE_APACHE_PEKKO, USE_APACHE_PEKKO_DESC).defaultValue(Boolean.valueOf(DEFAULT_USE_APACHE_PEKKO).toString()));
148+
cliOptions.add(CliOption.newString(PEKKO_HTTP_VERSION, PEKKO_HTTP_VERSION_DESC).defaultValue(pekkoHttpVersion));
144149

145150
importMapping.remove("Seq");
146151
importMapping.remove("List");
@@ -204,11 +209,16 @@ public void processOpts() {
204209
additionalProperties.put(USE_APACHE_PEKKO, useApachePekko);
205210
}
206211

212+
if (additionalProperties.containsKey(PEKKO_HTTP_VERSION)) {
213+
pekkoHttpVersion = (String) additionalProperties.get(PEKKO_HTTP_VERSION);
214+
} else {
215+
additionalProperties.put(PEKKO_HTTP_VERSION, DEFAULT_PEKKO_HTTP_VERSION);
216+
}
217+
207218
if (additionalProperties.containsKey(AKKA_HTTP_VERSION)) {
208219
akkaHttpVersion = (String) additionalProperties.get(AKKA_HTTP_VERSION);
209220
} else {
210-
String version = useApachePekko ? DEFAULT_PEKKO_HTTP_VERSION : DEFAULT_AKKA_HTTP_VERSION;
211-
additionalProperties.put(AKKA_HTTP_VERSION, version);
221+
additionalProperties.put(AKKA_HTTP_VERSION, akkaHttpVersion);
212222
}
213223

214224
if (useApachePekko) {

modules/openapi-generator/src/main/resources/scala-akka-http-server/build.sbt.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ organization := "{{groupId}}"
44
scalaVersion := "2.12.8"
55

66
libraryDependencies ++= Seq({{#useApachePekko}}
7-
"org.apache.pekko" %% "pekko-stream" % "{{akkaHttpVersion}}",
8-
"org.apache.pekko" %% "pekko-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
7+
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
8+
"org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
99
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
1010
"com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}
1111
)

samples/server/petstore/scala-pekko-http-server/build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ organization := "org.openapitools"
44
scalaVersion := "2.12.8"
55

66
libraryDependencies ++= Seq(
7-
"org.apache.pekko" %% "pekko-stream" % "1.0.0",
8-
"org.apache.pekko" %% "pekko-http" % "1.0.0"
7+
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
8+
"org.apache.pekko" %% "pekko-http" % "1.1.0"
99
)

0 commit comments

Comments
 (0)