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

Improve handling of pekko versions in scala-akka-http-server generator #20277

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generators/scala-akka-http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|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|
|modelPackage|package for generated models| |null|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
|pekkoHttpVersion|The version of pekko-http| |1.1.0|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
protected String akkaHttpVersion;
protected boolean generateAsManagedSources;
protected boolean useApachePekko;
protected String pekkoHttpVersion;

public static final String AKKA_HTTP_VERSION = "akkaHttpVersion";
public static final String AKKA_HTTP_VERSION_DESC = "The version of akka-http";
public static final String PEKKO_HTTP_VERSION = "pekkoHttpVersion";
public static final String PEKKO_HTTP_VERSION_DESC = "The version of pekko-http";
public static final String DEFAULT_AKKA_HTTP_VERSION = "10.1.10";
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.0.0";
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.1.0";

public static final String GENERATE_AS_MANAGED_SOURCES = "asManagedSources";
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";
Expand Down Expand Up @@ -124,6 +127,7 @@ public ScalaAkkaHttpServerCodegen() {
akkaHttpVersion = DEFAULT_AKKA_HTTP_VERSION;
generateAsManagedSources = DEFAULT_GENERATE_AS_MANAGED_SOURCES;
useApachePekko = DEFAULT_USE_APACHE_PEKKO;
pekkoHttpVersion = DEFAULT_PEKKO_HTTP_VERSION;

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

importMapping.remove("Seq");
importMapping.remove("List");
Expand Down Expand Up @@ -204,11 +209,16 @@ public void processOpts() {
additionalProperties.put(USE_APACHE_PEKKO, useApachePekko);
}

if (additionalProperties.containsKey(PEKKO_HTTP_VERSION)) {
pekkoHttpVersion = (String) additionalProperties.get(PEKKO_HTTP_VERSION);
} else {
additionalProperties.put(PEKKO_HTTP_VERSION, DEFAULT_PEKKO_HTTP_VERSION);
}

if (additionalProperties.containsKey(AKKA_HTTP_VERSION)) {
akkaHttpVersion = (String) additionalProperties.get(AKKA_HTTP_VERSION);
} else {
String version = useApachePekko ? DEFAULT_PEKKO_HTTP_VERSION : DEFAULT_AKKA_HTTP_VERSION;
additionalProperties.put(AKKA_HTTP_VERSION, version);
additionalProperties.put(AKKA_HTTP_VERSION, akkaHttpVersion);
}

if (useApachePekko) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ organization := "{{groupId}}"
scalaVersion := "2.12.8"

libraryDependencies ++= Seq({{#useApachePekko}}
"org.apache.pekko" %% "pekko-stream" % "{{akkaHttpVersion}}",
"org.apache.pekko" %% "pekko-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
"org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
"com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}
)
4 changes: 2 additions & 2 deletions samples/server/petstore/scala-pekko-http-server/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ organization := "org.openapitools"
scalaVersion := "2.12.8"

libraryDependencies ++= Seq(
"org.apache.pekko" %% "pekko-stream" % "1.0.0",
"org.apache.pekko" %% "pekko-http" % "1.0.0"
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
"org.apache.pekko" %% "pekko-http" % "1.1.0"
)
Loading