From eab6feeb4c95925b1c560f4f1cf028188147e5f0 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 17 Mar 2026 11:18:11 +0800 Subject: [PATCH 1/2] add scalafmt (plugin) to scala-sttp4 client --- .../languages/ScalaSttp4ClientCodegen.java | 19 +++++- .../scala-sttp4/project/plugins.mustache | 1 + .../resources/scala-sttp4/scalafmt.mustache | 63 +++++++++++++++++++ .../scala-sttp4/.openapi-generator/FILES | 3 +- .../petstore/scala-sttp4/.scalafmt.conf | 63 +++++++++++++++++++ .../petstore/scala-sttp4/project/plugins.sbt | 1 + 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/scala-sttp4/project/plugins.mustache create mode 100644 modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache create mode 100644 samples/client/petstore/scala-sttp4/.scalafmt.conf create mode 100644 samples/client/petstore/scala-sttp4/project/plugins.sbt diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttp4ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttp4ClientCodegen.java index 9c54671b8634..b628cb615500 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttp4ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttp4ClientCodegen.java @@ -1,3 +1,19 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.Operation; @@ -155,7 +171,8 @@ public void processOpts() { supportingFiles.add(new SupportingFile("jsonSupport.mustache", invokerFolder, "JsonSupport.scala")); supportingFiles.add(new SupportingFile("additionalTypeSerializers.mustache", invokerFolder, "AdditionalTypeSerializers.scala")); supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties")); - supportingFiles.add(new SupportingFile("dateSerializers.mustache", invokerFolder, "DateSerializers.scala")); + supportingFiles.add(new SupportingFile("project/plugins.mustache", "project", "plugins.sbt")); + supportingFiles.add(new SupportingFile("scalafmt.mustache", "", ".scalafmt.conf")); } @Override diff --git a/modules/openapi-generator/src/main/resources/scala-sttp4/project/plugins.mustache b/modules/openapi-generator/src/main/resources/scala-sttp4/project/plugins.mustache new file mode 100644 index 000000000000..eefc0dd27b23 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/scala-sttp4/project/plugins.mustache @@ -0,0 +1 @@ +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") diff --git a/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache b/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache new file mode 100644 index 000000000000..167ce829fb3d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache @@ -0,0 +1,63 @@ +version=3.10.6 +runner.dialect = scala213 +project { + git = true + excludeFilters = [ + scalafmt-benchmarks/src/resources, + sbt-test + bin/issue + ] + layout = StandardConvention +} +align { + preset = none + stripMargin = true +} +binPack { + importSelectors = fold +} +newlines { + avoidForSimpleOverflow = all + ignoreInSyntax = false + source = fold +} +rewrite { + rules = [ + AvoidInfix, + Imports, + RedundantBraces, + RedundantParens, + SortModifiers, + ] + imports { + selectors = fold + removeRedundantSelectors = true + sort = ascii + groups = [ + ["org\\.scalafmt\\..*"], + ["scala\\.meta\\..*", "org\\.scalameta\\..*"], + ["sbt\\..*"], + ["java.?\\..*"], + ["scala\\..*"], + ["org\\..*"], + ["com\\..*"], + ] + } + redundantBraces { + preset = all + oneStatApply { + parensMaxSpan = 300 + bracesMinSpan = 300 + } + } + redundantParens { + preset = all + } + sortModifiers.preset = styleGuide + trailingCommas.style = "always" +} +# Disabled in default since this operation is potentially +# dangerous if you define your own stripMargin with different +# semantics from the stdlib stripMargin. +assumeStandardLibraryStripMargin = true +onTestFailure = "To fix this, run ./scalafmt from the project root directory" diff --git a/samples/client/petstore/scala-sttp4/.openapi-generator/FILES b/samples/client/petstore/scala-sttp4/.openapi-generator/FILES index 93bed4b07d22..261dd9b57eb1 100644 --- a/samples/client/petstore/scala-sttp4/.openapi-generator/FILES +++ b/samples/client/petstore/scala-sttp4/.openapi-generator/FILES @@ -1,11 +1,12 @@ +.scalafmt.conf README.md build.sbt project/build.properties +project/plugins.sbt src/main/scala/org/openapitools/client/api/PetApi.scala src/main/scala/org/openapitools/client/api/StoreApi.scala src/main/scala/org/openapitools/client/api/UserApi.scala src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala -src/main/scala/org/openapitools/client/core/DateSerializers.scala src/main/scala/org/openapitools/client/core/JsonSupport.scala src/main/scala/org/openapitools/client/model/ApiResponse.scala src/main/scala/org/openapitools/client/model/Category.scala diff --git a/samples/client/petstore/scala-sttp4/.scalafmt.conf b/samples/client/petstore/scala-sttp4/.scalafmt.conf new file mode 100644 index 000000000000..167ce829fb3d --- /dev/null +++ b/samples/client/petstore/scala-sttp4/.scalafmt.conf @@ -0,0 +1,63 @@ +version=3.10.6 +runner.dialect = scala213 +project { + git = true + excludeFilters = [ + scalafmt-benchmarks/src/resources, + sbt-test + bin/issue + ] + layout = StandardConvention +} +align { + preset = none + stripMargin = true +} +binPack { + importSelectors = fold +} +newlines { + avoidForSimpleOverflow = all + ignoreInSyntax = false + source = fold +} +rewrite { + rules = [ + AvoidInfix, + Imports, + RedundantBraces, + RedundantParens, + SortModifiers, + ] + imports { + selectors = fold + removeRedundantSelectors = true + sort = ascii + groups = [ + ["org\\.scalafmt\\..*"], + ["scala\\.meta\\..*", "org\\.scalameta\\..*"], + ["sbt\\..*"], + ["java.?\\..*"], + ["scala\\..*"], + ["org\\..*"], + ["com\\..*"], + ] + } + redundantBraces { + preset = all + oneStatApply { + parensMaxSpan = 300 + bracesMinSpan = 300 + } + } + redundantParens { + preset = all + } + sortModifiers.preset = styleGuide + trailingCommas.style = "always" +} +# Disabled in default since this operation is potentially +# dangerous if you define your own stripMargin with different +# semantics from the stdlib stripMargin. +assumeStandardLibraryStripMargin = true +onTestFailure = "To fix this, run ./scalafmt from the project root directory" diff --git a/samples/client/petstore/scala-sttp4/project/plugins.sbt b/samples/client/petstore/scala-sttp4/project/plugins.sbt new file mode 100644 index 000000000000..eefc0dd27b23 --- /dev/null +++ b/samples/client/petstore/scala-sttp4/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") From 5579d8218d50100228c01588f56651d32eeb76b4 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 17 Mar 2026 11:34:20 +0800 Subject: [PATCH 2/2] update --- .../src/main/resources/scala-sttp4/scalafmt.mustache | 7 +------ samples/client/petstore/scala-sttp4/.scalafmt.conf | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache b/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache index 167ce829fb3d..e66032cc83c3 100644 --- a/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache +++ b/modules/openapi-generator/src/main/resources/scala-sttp4/scalafmt.mustache @@ -1,7 +1,7 @@ version=3.10.6 runner.dialect = scala213 project { - git = true + git = false excludeFilters = [ scalafmt-benchmarks/src/resources, sbt-test @@ -56,8 +56,3 @@ rewrite { sortModifiers.preset = styleGuide trailingCommas.style = "always" } -# Disabled in default since this operation is potentially -# dangerous if you define your own stripMargin with different -# semantics from the stdlib stripMargin. -assumeStandardLibraryStripMargin = true -onTestFailure = "To fix this, run ./scalafmt from the project root directory" diff --git a/samples/client/petstore/scala-sttp4/.scalafmt.conf b/samples/client/petstore/scala-sttp4/.scalafmt.conf index 167ce829fb3d..e66032cc83c3 100644 --- a/samples/client/petstore/scala-sttp4/.scalafmt.conf +++ b/samples/client/petstore/scala-sttp4/.scalafmt.conf @@ -1,7 +1,7 @@ version=3.10.6 runner.dialect = scala213 project { - git = true + git = false excludeFilters = [ scalafmt-benchmarks/src/resources, sbt-test @@ -56,8 +56,3 @@ rewrite { sortModifiers.preset = styleGuide trailingCommas.style = "always" } -# Disabled in default since this operation is potentially -# dangerous if you define your own stripMargin with different -# semantics from the stdlib stripMargin. -assumeStandardLibraryStripMargin = true -onTestFailure = "To fix this, run ./scalafmt from the project root directory"