Skip to content

Commit ab17676

Browse files
authored
Add scalafmt plugin to scala-sttp4-jsoniter client generator (#23378)
* Add scalafmt plugin to scala-sttp4-jsoniter client generator * Regenerate samples after rebase
1 parent 3029054 commit ab17676

10 files changed

Lines changed: 142 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public void processOpts() {
187187
supportingFiles.add(new SupportingFile("helpers.mustache", invokerFolder,
188188
"Helpers.scala"));
189189
supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties"));
190+
supportingFiles.add(new SupportingFile("project/plugins.mustache", "project", "plugins.sbt"));
191+
supportingFiles.add(new SupportingFile("scalafmt.mustache", "", ".scalafmt.conf"));
190192
}
191193

192194
@Override
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version=3.10.6
2+
runner.dialect = scala213
3+
project {
4+
git = false
5+
excludeFilters = [
6+
scalafmt-benchmarks/src/resources,
7+
sbt-test
8+
bin/issue
9+
]
10+
layout = StandardConvention
11+
}
12+
align {
13+
preset = none
14+
stripMargin = true
15+
}
16+
binPack {
17+
importSelectors = fold
18+
}
19+
newlines {
20+
avoidForSimpleOverflow = all
21+
ignoreInSyntax = false
22+
source = fold
23+
}
24+
rewrite {
25+
rules = [
26+
AvoidInfix,
27+
Imports,
28+
RedundantBraces,
29+
RedundantParens,
30+
SortModifiers,
31+
]
32+
imports {
33+
selectors = fold
34+
removeRedundantSelectors = true
35+
sort = ascii
36+
groups = [
37+
["org\\.scalafmt\\..*"],
38+
["scala\\.meta\\..*", "org\\.scalameta\\..*"],
39+
["sbt\\..*"],
40+
["java.?\\..*"],
41+
["scala\\..*"],
42+
["org\\..*"],
43+
["com\\..*"],
44+
]
45+
}
46+
redundantBraces {
47+
preset = all
48+
oneStatApply {
49+
parensMaxSpan = 300
50+
bracesMinSpan = 300
51+
}
52+
}
53+
redundantParens {
54+
preset = all
55+
}
56+
sortModifiers.preset = styleGuide
57+
trailingCommas.style = "always"
58+
}

samples/client/petstore/scala-sttp4-jsoniter/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
.scalafmt.conf
12
README.md
23
build.sbt
34
project/build.properties
5+
project/plugins.sbt
46
src/main/scala/org/openapitools/client/api/PetApi.scala
57
src/main/scala/org/openapitools/client/api/StoreApi.scala
68
src/main/scala/org/openapitools/client/api/UserApi.scala
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version=3.10.6
2+
runner.dialect = scala213
3+
project {
4+
git = false
5+
excludeFilters = [
6+
scalafmt-benchmarks/src/resources,
7+
sbt-test
8+
bin/issue
9+
]
10+
layout = StandardConvention
11+
}
12+
align {
13+
preset = none
14+
stripMargin = true
15+
}
16+
binPack {
17+
importSelectors = fold
18+
}
19+
newlines {
20+
avoidForSimpleOverflow = all
21+
ignoreInSyntax = false
22+
source = fold
23+
}
24+
rewrite {
25+
rules = [
26+
AvoidInfix,
27+
Imports,
28+
RedundantBraces,
29+
RedundantParens,
30+
SortModifiers,
31+
]
32+
imports {
33+
selectors = fold
34+
removeRedundantSelectors = true
35+
sort = ascii
36+
groups = [
37+
["org\\.scalafmt\\..*"],
38+
["scala\\.meta\\..*", "org\\.scalameta\\..*"],
39+
["sbt\\..*"],
40+
["java.?\\..*"],
41+
["scala\\..*"],
42+
["org\\..*"],
43+
["com\\..*"],
44+
]
45+
}
46+
redundantBraces {
47+
preset = all
48+
oneStatApply {
49+
parensMaxSpan = 300
50+
bracesMinSpan = 300
51+
}
52+
}
53+
redundantParens {
54+
preset = all
55+
}
56+
sortModifiers.preset = styleGuide
57+
trailingCommas.style = "always"
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")

samples/server/others/kotlin-server/polymorphism-allof-and-discriminator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# org.openapitools.server - Kotlin Server library for Polymorphism example with allOf and discriminator
1+
# org.openapitools.server - Kotlin Server library for Basic polymorphism example with discriminator
22

33
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44

samples/server/others/kotlin-server/polymorphism-allof-and-discriminator/src/main/kotlin/org/openapitools/server/models/Cat.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Polymorphism example with allOf and discriminator
2+
* Basic polymorphism example with discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,24 +11,22 @@
1111
*/
1212
package org.openapitools.server.models
1313

14-
import org.openapitools.server.models.Pet
1514

1615
/**
17-
* A representation of a cat
16+
* A pet cat
1817
* @param huntingSkill The measured skill for hunting
18+
* @param petType
1919
*/
2020
data class Cat(
2121
/* The measured skill for hunting */
2222

2323
@field:com.fasterxml.jackson.annotation.JsonProperty("huntingSkill")
2424
val huntingSkill: Cat.HuntingSkill,
2525

26-
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
27-
override val name: kotlin.String,
28-
2926
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
30-
override val petType: kotlin.String
31-
) : Pet(name = name, petType = petType)
27+
override val petType: kotlin.String = "cat",
28+
29+
) : Pet(petType = petType)
3230
{
3331
/**
3432
* The measured skill for hunting
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Polymorphism example with allOf and discriminator
2+
* Basic polymorphism example with discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,24 +11,19 @@
1111
*/
1212
package org.openapitools.server.models
1313

14-
import org.openapitools.server.models.Pet
1514

1615
/**
17-
* A representation of a dog
16+
* A pet dog
17+
* @param petType
1818
* @param packSize the size of the pack the dog is from
1919
*/
2020
data class Dog(
21+
22+
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
23+
override val petType: kotlin.String = "dog",
2124
/* the size of the pack the dog is from */
2225

2326
@field:com.fasterxml.jackson.annotation.JsonProperty("packSize")
24-
val packSize: kotlin.Int = 0,
25-
26-
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
27-
override val name: kotlin.String,
28-
29-
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
30-
override val petType: kotlin.String
31-
) : Pet(name = name, petType = petType)
32-
{
33-
}
27+
val packSize: kotlin.Int = 0
28+
) : Pet(petType = petType)
3429

samples/server/others/kotlin-server/polymorphism-allof-and-discriminator/src/main/kotlin/org/openapitools/server/models/Pet.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Polymorphism example with allOf and discriminator
2+
* Basic polymorphism example with discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,23 +11,20 @@
1111
*/
1212
package org.openapitools.server.models
1313

14+
import org.openapitools.server.models.Cat
15+
import org.openapitools.server.models.Dog
1416

1517
/**
1618
*
17-
* @param name
1819
* @param petType
1920
*/
2021
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "petType", visible = true)
2122
@com.fasterxml.jackson.annotation.JsonSubTypes(
22-
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Cat::class, name = "Cat"),
23-
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Dog::class, name = "Dog")
23+
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Cat::class, name = "cat"),
24+
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Dog::class, name = "dog")
2425
)
2526
sealed class Pet(
2627

27-
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
28-
open val name: kotlin.String
29-
,
30-
3128
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
3229
open val petType: kotlin.String
3330

0 commit comments

Comments
 (0)