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
This commit is contained in:
Daniel Åkerlund 2024-12-11 05:31:22 +01:00 committed by GitHub
parent e7b5f348e7
commit b218e238f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -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| |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| |modelPackage|package for generated models| |null|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| |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| |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| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|

View File

@ -45,11 +45,14 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
protected String akkaHttpVersion; protected String akkaHttpVersion;
protected boolean generateAsManagedSources; protected boolean generateAsManagedSources;
protected boolean useApachePekko; protected boolean useApachePekko;
protected String pekkoHttpVersion;
public static final String AKKA_HTTP_VERSION = "akkaHttpVersion"; 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 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_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 = "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"; 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 class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
akkaHttpVersion = DEFAULT_AKKA_HTTP_VERSION; akkaHttpVersion = DEFAULT_AKKA_HTTP_VERSION;
generateAsManagedSources = DEFAULT_GENERATE_AS_MANAGED_SOURCES; generateAsManagedSources = DEFAULT_GENERATE_AS_MANAGED_SOURCES;
useApachePekko = DEFAULT_USE_APACHE_PEKKO; useApachePekko = DEFAULT_USE_APACHE_PEKKO;
pekkoHttpVersion = DEFAULT_PEKKO_HTTP_VERSION;
setReservedWordsLowerCase( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
@ -141,6 +145,7 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
cliOptions.add(CliOption.newString(AKKA_HTTP_VERSION, AKKA_HTTP_VERSION_DESC).defaultValue(akkaHttpVersion)); 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(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.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("Seq");
importMapping.remove("List"); importMapping.remove("List");
@ -204,11 +209,16 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
additionalProperties.put(USE_APACHE_PEKKO, useApachePekko); 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)) { if (additionalProperties.containsKey(AKKA_HTTP_VERSION)) {
akkaHttpVersion = (String) additionalProperties.get(AKKA_HTTP_VERSION); akkaHttpVersion = (String) additionalProperties.get(AKKA_HTTP_VERSION);
} else { } else {
String version = useApachePekko ? DEFAULT_PEKKO_HTTP_VERSION : DEFAULT_AKKA_HTTP_VERSION; additionalProperties.put(AKKA_HTTP_VERSION, akkaHttpVersion);
additionalProperties.put(AKKA_HTTP_VERSION, version);
} }
if (useApachePekko) { if (useApachePekko) {

View File

@ -4,8 +4,8 @@ organization := "{{groupId}}"
scalaVersion := "2.12.8" scalaVersion := "2.12.8"
libraryDependencies ++= Seq({{#useApachePekko}} libraryDependencies ++= Seq({{#useApachePekko}}
"org.apache.pekko" %% "pekko-stream" % "{{akkaHttpVersion}}", "org.apache.pekko" %% "pekko-stream" % "1.0.3",
"org.apache.pekko" %% "pekko-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}} "org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
"com.typesafe.akka" %% "akka-stream" % "2.5.21", "com.typesafe.akka" %% "akka-stream" % "2.5.21",
"com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}} "com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}
) )

View File

@ -4,6 +4,6 @@ organization := "org.openapitools"
scalaVersion := "2.12.8" scalaVersion := "2.12.8"
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.apache.pekko" %% "pekko-stream" % "1.0.0", "org.apache.pekko" %% "pekko-stream" % "1.0.3",
"org.apache.pekko" %% "pekko-http" % "1.0.0" "org.apache.pekko" %% "pekko-http" % "1.1.0"
) )