From 4bad43becadb132812196ca63bf0db520c143cb1 Mon Sep 17 00:00:00 2001 From: YB0y Date: Fri, 27 Mar 2026 11:52:40 +0000 Subject: [PATCH] Add scalafmt plugin to scala-sttp client generator --- .../languages/ScalaSttpClientCodegen.java | 2 + .../scala-sttp/project/plugins.mustache | 1 + .../resources/scala-sttp/scalafmt.mustache | 58 +++++++++++++++++++ .../scala-sttp-circe/.openapi-generator/FILES | 2 + .../petstore/scala-sttp-circe/.scalafmt.conf | 58 +++++++++++++++++++ .../scala-sttp-circe/project/plugins.sbt | 1 + .../scala-sttp/.openapi-generator/FILES | 2 + .../client/petstore/scala-sttp/.scalafmt.conf | 58 +++++++++++++++++++ .../petstore/scala-sttp/project/plugins.sbt | 1 + 9 files changed, 183 insertions(+) create mode 100644 modules/openapi-generator/src/main/resources/scala-sttp/project/plugins.mustache create mode 100644 modules/openapi-generator/src/main/resources/scala-sttp/scalafmt.mustache create mode 100644 samples/client/petstore/scala-sttp-circe/.scalafmt.conf create mode 100644 samples/client/petstore/scala-sttp-circe/project/plugins.sbt create mode 100644 samples/client/petstore/scala-sttp/.scalafmt.conf create mode 100644 samples/client/petstore/scala-sttp/project/plugins.sbt diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java index f4aa0e66327d..8e5c9ec22df9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java @@ -172,6 +172,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("project/plugins.mustache", "project", "plugins.sbt")); + supportingFiles.add(new SupportingFile("scalafmt.mustache", "", ".scalafmt.conf")); supportingFiles.add(new SupportingFile("dateSerializers.mustache", invokerFolder, "DateSerializers.scala")); } diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/project/plugins.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/project/plugins.mustache new file mode 100644 index 000000000000..eefc0dd27b23 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/scala-sttp/project/plugins.mustache @@ -0,0 +1 @@ +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/scalafmt.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/scalafmt.mustache new file mode 100644 index 000000000000..e66032cc83c3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/scala-sttp/scalafmt.mustache @@ -0,0 +1,58 @@ +version=3.10.6 +runner.dialect = scala213 +project { + git = false + 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" +} diff --git a/samples/client/petstore/scala-sttp-circe/.openapi-generator/FILES b/samples/client/petstore/scala-sttp-circe/.openapi-generator/FILES index 80b204182f1b..7e661202c5c2 100644 --- a/samples/client/petstore/scala-sttp-circe/.openapi-generator/FILES +++ b/samples/client/petstore/scala-sttp-circe/.openapi-generator/FILES @@ -1,6 +1,8 @@ +.scalafmt.conf README.md build.sbt project/build.properties +project/plugins.sbt src/main/scala/org/openapitools/client/api/FakeApi.scala src/main/scala/org/openapitools/client/api/PetApi.scala src/main/scala/org/openapitools/client/api/StoreApi.scala diff --git a/samples/client/petstore/scala-sttp-circe/.scalafmt.conf b/samples/client/petstore/scala-sttp-circe/.scalafmt.conf new file mode 100644 index 000000000000..e66032cc83c3 --- /dev/null +++ b/samples/client/petstore/scala-sttp-circe/.scalafmt.conf @@ -0,0 +1,58 @@ +version=3.10.6 +runner.dialect = scala213 +project { + git = false + 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" +} diff --git a/samples/client/petstore/scala-sttp-circe/project/plugins.sbt b/samples/client/petstore/scala-sttp-circe/project/plugins.sbt new file mode 100644 index 000000000000..eefc0dd27b23 --- /dev/null +++ b/samples/client/petstore/scala-sttp-circe/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") diff --git a/samples/client/petstore/scala-sttp/.openapi-generator/FILES b/samples/client/petstore/scala-sttp/.openapi-generator/FILES index 80b204182f1b..7e661202c5c2 100644 --- a/samples/client/petstore/scala-sttp/.openapi-generator/FILES +++ b/samples/client/petstore/scala-sttp/.openapi-generator/FILES @@ -1,6 +1,8 @@ +.scalafmt.conf README.md build.sbt project/build.properties +project/plugins.sbt src/main/scala/org/openapitools/client/api/FakeApi.scala src/main/scala/org/openapitools/client/api/PetApi.scala src/main/scala/org/openapitools/client/api/StoreApi.scala diff --git a/samples/client/petstore/scala-sttp/.scalafmt.conf b/samples/client/petstore/scala-sttp/.scalafmt.conf new file mode 100644 index 000000000000..e66032cc83c3 --- /dev/null +++ b/samples/client/petstore/scala-sttp/.scalafmt.conf @@ -0,0 +1,58 @@ +version=3.10.6 +runner.dialect = scala213 +project { + git = false + 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" +} diff --git a/samples/client/petstore/scala-sttp/project/plugins.sbt b/samples/client/petstore/scala-sttp/project/plugins.sbt new file mode 100644 index 000000000000..eefc0dd27b23 --- /dev/null +++ b/samples/client/petstore/scala-sttp/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")