Skip to content

Commit a2766e9

Browse files
Update scalafmt-core to 3.6.1 (#215)
* Update scalafmt-core to 3.6.1 * Reformat with scalafmt 3.6.1 Executed command: scalafmt --non-interactive * Add 'Reformat with scalafmt 3.6.1' to .git-blame-ignore-revs
1 parent de31225 commit a2766e9

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Scala Steward: Reformat with scalafmt 3.6.1
2+
8790252edd105e64912f6e12da1ac2aa404c6fd8

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://scalameta.org/scalafmt/docs/configuration.html
2-
version = "3.5.9"
2+
version = "3.6.1"
33
runner.dialect = scala213source3
44
maxColumn = 140
55
project.git = true

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ ThisBuild / githubWorkflowBuildPostamble := Seq(
152152
cond = Some("startsWith(matrix.scala, '2.13')")
153153
)
154154
)
155-
*/
155+
*/
156156

157157
ThisBuild / githubWorkflowPublish := Seq(
158158
WorkflowStep.Sbt(

src/main/scala-2/com/github/swagger/scala/converter/SubtypeHelper.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ object SubtypeHelper {
1616
if (classSymbol.isJava) {
1717
Seq.empty
1818
} else if (symbol.isClass) {
19-
symbol.asClass.knownDirectSubclasses
20-
.toSeq
19+
symbol.asClass.knownDirectSubclasses.toSeq
2120
.sortBy(_.info.toString)
2221
.flatMap(s => if (s.isClass) Some(s.asClass) else None)
2322
.map(c => mirror.runtimeClass(c))

src/main/scala/com/github/swagger/scala/converter/SwaggerScalaModelConverter.scala

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ object SwaggerScalaModelConverter {
3030
private var requiredBasedOnDefaultValue = true
3131

3232
/** If you use swagger annotations to override what is automatically derived, then be aware that
33-
* [[io.swagger.v3.oas.annotations.media.Schema]] annotation has required = false, by default. You are advised to set the required
34-
* flag on this annotation to the correct value. If you would prefer to have the Schema annotation required flag ignored and to rely on
35-
* the this module inferring the value (as it would if you don't annotate the classes or fields), then set
33+
* [[io.swagger.v3.oas.annotations.media.Schema]] annotation has required = false, by default. You are advised to set the required flag
34+
* on this annotation to the correct value. If you would prefer to have the Schema annotation required flag ignored and to rely on the
35+
* this module inferring the value (as it would if you don't annotate the classes or fields), then set
3636
* [[SwaggerScalaModelConverter.setRequiredBasedOnAnnotation]] to true and the required property on the annotation will be ignored,
3737
* unless the field is an [[Option]].
3838
*
@@ -44,11 +44,11 @@ object SwaggerScalaModelConverter {
4444
requiredBasedOnAnnotation = value
4545
}
4646

47-
/** If you use swagger annotations to override what is automatically derived, then this flag will not be used.
48-
* If you rely on this module inferring the required flag (as it would if you don't annotate the classes or fields),
49-
* then this flag will control how the required flag is derived when a default value exists.
50-
* If [[SwaggerScalaModelConverter.setRequiredBasedOnDefaultValue]] is true and a property has a default value, then it will not be required.
51-
* However, if this flag is false, then a property will be required only if it's not an [[Option]].
47+
/** If you use swagger annotations to override what is automatically derived, then this flag will not be used. If you rely on this module
48+
* inferring the required flag (as it would if you don't annotate the classes or fields), then this flag will control how the required
49+
* flag is derived when a default value exists. If [[SwaggerScalaModelConverter.setRequiredBasedOnDefaultValue]] is true and a property
50+
* has a default value, then it will not be required. However, if this flag is false, then a property will be required only if it's not
51+
* an [[Option]].
5252
*
5353
* @param value
5454
* true by default
@@ -59,28 +59,28 @@ object SwaggerScalaModelConverter {
5959
}
6060

6161
/** If you use swagger annotations to override what is automatically derived, then be aware that
62-
* [[io.swagger.v3.oas.annotations.media.Schema]] annotation has required = false, by default. You are advised to set the required
63-
* flag on this annotation to the correct value. If you would prefer to have the Schema annotation required flag ignored and to rely on
64-
* the this module inferring the value (as it would if you don't annotate the classes or fields), then set
62+
* [[io.swagger.v3.oas.annotations.media.Schema]] annotation has required = false, by default. You are advised to set the required flag
63+
* on this annotation to the correct value. If you would prefer to have the Schema annotation required flag ignored and to rely on the
64+
* this module inferring the value (as it would if you don't annotate the classes or fields), then set
6565
* [[SwaggerScalaModelConverter.setRequiredBasedOnAnnotation]] to true and the required property on the annotation will be ignored,
6666
* unless the field is an [[Option]].
6767
*
68-
* @return value
69-
* value: true by default
68+
* @return
69+
* value value: true by default
7070
* @since v2.7.4
7171
*/
7272
def isRequiredBasedOnAnnotation: Boolean = requiredBasedOnAnnotation
7373

74-
/** If you use swagger annotations to override what is automatically derived, then this flag will not be used.
75-
* If you rely on this module inferring the required flag (as it would if you don't annotate the classes or fields),
76-
* then this flag will control how the required flag is derived when a default value exists.
77-
* If [[SwaggerScalaModelConverter.setRequiredBasedOnDefaultValue]] is true and a property has a default value, then it will not be required.
78-
* However, if this flag is false, then a property will be required only if it's not an [[Option]].
74+
/** If you use swagger annotations to override what is automatically derived, then this flag will not be used. If you rely on this module
75+
* inferring the required flag (as it would if you don't annotate the classes or fields), then this flag will control how the required
76+
* flag is derived when a default value exists. If [[SwaggerScalaModelConverter.setRequiredBasedOnDefaultValue]] is true and a property
77+
* has a default value, then it will not be required. However, if this flag is false, then a property will be required only if it's not
78+
* an [[Option]].
7979
*
8080
* @return
8181
* value: true by default
8282
* @since v2.7.6
83-
*/
83+
*/
8484
def isRequiredBasedOnDefaultValue: Boolean = requiredBasedOnDefaultValue
8585
}
8686

@@ -118,8 +118,12 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
118118
}
119119
}
120120

121-
private def resolveWithoutSubtypes(javaType: JavaType, `type`: AnnotatedType, context: ModelConverterContext,
122-
chain: util.Iterator[ModelConverter]): Schema[_] = {
121+
private def resolveWithoutSubtypes(
122+
javaType: JavaType,
123+
`type`: AnnotatedType,
124+
context: ModelConverterContext,
125+
chain: util.Iterator[ModelConverter]
126+
): Schema[_] = {
123127
val cls = javaType.getRawClass
124128
matchScalaPrimitives(`type`, cls).getOrElse {
125129
// Unbox scala options
@@ -128,7 +132,7 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
128132
val baseType =
129133
if (
130134
SwaggerScalaModelConverter.isRequiredBasedOnAnnotation
131-
&& annotatedOverrides.headOption.getOrElse(false)
135+
&& annotatedOverrides.headOption.getOrElse(false)
132136
) new AnnotatedType()
133137
else new AnnotatedTypeForOption()
134138
resolve(nextType(baseType, `type`, javaType), context, chain)
@@ -198,7 +202,7 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
198202
case _ => {
199203
defaultValue match {
200204
case Some(wrappedValue) => property.setDefault(wrappedValue)
201-
case None => //no default
205+
case None => // no default
202206
case seq: Seq[_] => property.setDefault(seq.asJava)
203207
case set: Set[_] => property.setDefault(set.asJava)
204208
case dv => property.setDefault(dv)
@@ -317,7 +321,6 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
317321
}
318322
}
319323

320-
321324
private def getRequiredSettings(annotatedType: AnnotatedType): Seq[Boolean] = annotatedType match {
322325
case _: AnnotatedTypeForOption => Seq.empty
323326
case _ => getRequiredSettings(nullSafeSeq(annotatedType.getCtxAnnotations))

src/test/scala/com/github/swagger/scala/converter/ModelPropertyParserTest.scala

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
2929
val converter = ModelConverters.getInstance()
3030
}
3131

32-
class PropertiesScope[A](requiredBasedAnnotation: Boolean = true, requiredBasedDefaultValue: Boolean = true, debug: Boolean = false)(implicit tt: ClassTag[A]) extends TestScope {
32+
class PropertiesScope[A](requiredBasedAnnotation: Boolean = true, requiredBasedDefaultValue: Boolean = true, debug: Boolean = false)(
33+
implicit tt: ClassTag[A]
34+
) extends TestScope {
3335
SwaggerScalaModelConverter.setRequiredBasedOnAnnotation(requiredBasedAnnotation)
3436
SwaggerScalaModelConverter.setRequiredBasedOnDefaultValue(requiredBasedDefaultValue)
3537
val schemas = converter.readAll(tt.runtimeClass).asScala.toMap
@@ -161,7 +163,8 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
161163
}
162164

163165
it should "prioritize required as specified in annotation by default" in new PropertiesScope[ModelWOptionIntSchemaOverrideForRequired](
164-
true, true
166+
true,
167+
true
165168
) {
166169
val requiredIntWithDefault = model.value.getProperties.get("requiredIntWithDefault")
167170
requiredIntWithDefault shouldBe an[IntegerSchema]
@@ -186,8 +189,11 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
186189
nullSafeSeq(model.value.getRequired).toSet shouldEqual Set("annotatedOptionalInt", "requiredInt")
187190
}
188191

189-
it should "prioritize required as specified in annotation and not based on default value" in new PropertiesScope[ModelWOptionIntSchemaOverrideForRequired](
190-
true, false
192+
it should "prioritize required as specified in annotation and not based on default value" in new PropertiesScope[
193+
ModelWOptionIntSchemaOverrideForRequired
194+
](
195+
true,
196+
false
191197
) {
192198
val requiredIntWithDefault = model.value.getProperties.get("requiredIntWithDefault")
193199
requiredIntWithDefault shouldBe an[IntegerSchema]
@@ -263,7 +269,14 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
263269
annotatedOptionalStringWithNoneDefault shouldBe an[StringSchema]
264270
annotatedOptionalStringWithNoneDefault.asInstanceOf[StringSchema].getDefault should be(null)
265271

266-
nullSafeSeq(model.value.getRequired).toSet shouldEqual Set("requiredInt", "requiredIntWithDefault", "annotatedRequiredInt", "annotatedRequiredIntWithDefault", "annotatedIntWithDefault", "annotatedOptionalInt")
272+
nullSafeSeq(model.value.getRequired).toSet shouldEqual Set(
273+
"requiredInt",
274+
"requiredIntWithDefault",
275+
"annotatedRequiredInt",
276+
"annotatedRequiredIntWithDefault",
277+
"annotatedIntWithDefault",
278+
"annotatedOptionalInt"
279+
)
267280
}
268281

269282
it should "consider fields that aren't optional required if `requiredBasedAnnotation == true`" in new PropertiesScope[

src/test/scala/models/Animal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class Dog(val name: String) extends Animal("Dog")
88

99
class Cat(val name: String, val age: Int) extends Animal("Cat")
1010

11-
case class PetOwner(owner: String, pet: Animal)
11+
case class PetOwner(owner: String, pet: Animal)

src/test/scala/models/ModelWBigDecimalAnnotated.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package models
33
import io.swagger.v3.oas.annotations.media.Schema
44

55
case class ModelWBigDecimalAnnotated(
6-
@Schema(description = "bigdecimal value", `type` = "string", example = "42.0",
7-
required = true, deprecated = true) field: BigDecimal
6+
@Schema(description = "bigdecimal value", `type` = "string", example = "42.0", required = true, deprecated = true) field: BigDecimal
87
)
98

109
case class ModelWBigDecimalNoType(field: BigDecimal)

0 commit comments

Comments
 (0)