Skip to content

Commit

Permalink
Merge pull request #1903 from blast-hardcheese/1899-fixup
Browse files Browse the repository at this point in the history
Introducing a delay in the name generator, since `Target` is not `Lazy`
  • Loading branch information
blast-hardcheese authored Dec 23, 2023
2 parents 585c2f2 + 19d1d9c commit 3482f33
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ object ModelResolver {
Fw: FrameworkTerms[L, F]
): F[Either[core.LazyResolvedType[L], core.Resolved[L]]] = propMetaImpl[L, F](property, components)(Left(_))

def propMetaWithName[L <: LA, F[_]: Monad](tpe: F[L#Type], property: Tracker[Schema[_]], components: Tracker[Option[Components]])(implicit
def propMetaWithName[L <: LA, F[_]: Monad](tpe: Function0[F[L#Type]], property: Tracker[Schema[_]], components: Tracker[Option[Components]])(implicit
Sc: LanguageTerms[L, F],
Cl: CollectionsLibTerms[L, F],
Sw: OpenAPITerms[L, F],
Fw: FrameworkTerms[L, F]
): F[Either[core.LazyResolvedType[L], core.Resolved[L]]] =
propMetaImpl(property, components)(
_.refine[F[core.Resolved[L]]] { case ObjectExtractor(schema) if Option(schema.getProperties).exists(p => !p.isEmpty) => schema }(_ =>
tpe.map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty))
).orRefine { case c: ComposedSchema => c }(_ => tpe.map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty)))
tpe().map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty))
).orRefine { case c: ComposedSchema => c }(_ => tpe().map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty)))
.orRefine { case schema: StringSchema if Option(schema.getEnum).map(_.asScala).exists(_.nonEmpty) => schema }(_ =>
tpe.map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty))
tpe().map(core.Resolved[L](_, None, None, ReifiedRawType.unsafeEmpty))
)
.map(_.map(r => r.pure[Either[core.LazyResolvedType[L], *]]))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class JacksonGenerator private (implicit Cl: CollectionsLibTerms[JavaLanguage, T
typeName <- formatTypeName(name).map(formattedName => getClsName(name).append(formattedName))
tpe <- selectType(typeName)
maybeNestedDefinition <- processProperty(name, schema)
resolvedType <- ModelResolver.propMetaWithName[JavaLanguage, Target](Target.pure(tpe), schema, components)
resolvedType <- ModelResolver.propMetaWithName[JavaLanguage, Target](() => Target.pure(tpe), schema, components)
prefixes <- vendorPrefixes()
propertyRequirement = getPropertyRequirement(schema, requiredFields.contains(name), defaultPropertyRequirement)
defValue <- defaultValue(typeName, schema, propertyRequirement, definitions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Issue195 extends AnyFunSpec with Matchers {
emit("TypeA", () => TypeA("foo"), Json.obj("type" -> Json.fromString("foo"), "beepBorp" -> Json.fromString("typea")))
emit("TypeB", () => TypeB("foo"), Json.obj("type" -> Json.fromString("foo"), "beepBorp" -> Json.fromString("TypeB")))
emit("TypeC", () => Foo.WrappedC(TypeC("foo")), Json.obj("C" -> Json.obj("type" -> Json.fromString("foo")), "beepBorp" -> Json.fromString("WrappedC")))
emit("typed", () => Foo.Nested1(Typed("foo")), Json.obj("D" -> Json.obj("type" -> Json.fromString("foo")), "beepBorp" -> Json.fromString("Nested1")))
emit("TypeE", () => TypeE("foo"), Json.obj("type" -> Json.fromString("foo"), "beepBorp" -> Json.fromString("TypeE")))
emit("typed", () => Foo.Nested2(Typed("foo")), Json.obj("D" -> Json.obj("type" -> Json.fromString("foo")), "beepBorp" -> Json.fromString("Nested2")))
emit("TypeE", () => Foo.Nested3(TypeE("foo")), Json.obj("E" -> Json.obj("type" -> Json.fromString("foo")), "beepBorp" -> Json.fromString("Nested3")))
}
}
6 changes: 5 additions & 1 deletion modules/sample/src/main/resources/issues/issue195.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ components:
properties:
D:
$ref: '#/components/schemas/typed'
- $ref: '#/components/schemas/TypeE'
- type: object
required: [E]
properties:
E:
$ref: '#/components/schemas/TypeE'
discriminator:
propertyName: beepBorp
mapping:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
.fold[Target[Either[String, StrictProtocolElems[ScalaLanguage]]]](Target.pure(Left("Does not have oneOf"))) { xs =>
for {
nameGenerator <- Target.pure(new java.util.concurrent.atomic.AtomicInteger(1))
getNewName = Target.pure(nameGenerator).map(ng => s"Nested${ng.getAndIncrement()}")
getNewName = () => Target.pure(nameGenerator).map(ng => s"Nested${ng.getAndIncrement()}")
(rawTypes, nestedClasses) <- xs
.traverse { model =>
for {
resolved <- ModelResolver.propMetaWithName[ScalaLanguage, Target](getNewName.flatMap(Sc.pureTypeName), model, components)
resolved <- ModelResolver.propMetaWithName[ScalaLanguage, Target](() => getNewName().flatMap(Sc.pureTypeName), model, components)
(rawType, nestedClasses) <- resolved
.bitraverse(
deferred => Target.fromOption(concreteTypes.find(_.clsName == deferred.value), UserError("Not supported")),
Expand Down Expand Up @@ -816,7 +816,7 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
typeName <- formatTypeName(name).map(formattedName => getClsName(name).append(formattedName))
tpe <- selectType(typeName)
maybeNestedDefinition <- processProperty(name, schema)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](Target.pure(tpe), schema, components)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](() => Target.pure(tpe), schema, components)
propertyRequirement = getPropertyRequirement(schema, requiredFields.contains(name), defaultPropertyRequirement)
defValue <- defaultValue(typeName, schema, propertyRequirement, definitions)
fieldName <- formatFieldName(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,11 @@ class CirceRefinedProtocolGenerator private (circeVersion: CirceModelGenerator,
.fold[Target[Either[String, StrictProtocolElems[ScalaLanguage]]]](Target.pure(Left("Does not have oneOf"))) { xs =>
for {
nameGenerator <- Target.pure(new java.util.concurrent.atomic.AtomicInteger(1))
getNewName = Target.pure(nameGenerator).map(ng => s"Nested${ng.getAndIncrement()}")
getNewName = () => Target.pure(nameGenerator).map(ng => s"Nested${ng.getAndIncrement()}")
(rawTypes, nestedClasses) <- xs
.traverse { model =>
for {
resolved <- ModelResolver.propMetaWithName[ScalaLanguage, Target](getNewName.flatMap(Sc.pureTypeName), model, components)
resolved <- ModelResolver.propMetaWithName[ScalaLanguage, Target](() => getNewName().flatMap(Sc.pureTypeName), model, components)
(rawType, nestedClasses) <- resolved
.bitraverse(
deferred => Target.fromOption(concreteTypes.find(_.clsName == deferred.value), UserError("Not supported")),
Expand Down Expand Up @@ -888,7 +888,7 @@ class CirceRefinedProtocolGenerator private (circeVersion: CirceModelGenerator,
typeName <- formatTypeName(name).map(formattedName => getClsName(name).append(formattedName))
tpe <- selectType(typeName)
maybeNestedDefinition <- processProperty(name, schema)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](Target.pure(tpe), schema, components)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](() => Target.pure(tpe), schema, components)
propertyRequirement = getPropertyRequirement(schema, requiredFields.contains(name), defaultPropertyRequirement)
defValue <- defaultValue(typeName, schema, propertyRequirement, definitions)
fieldName <- formatFieldName(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ class JacksonProtocolGenerator private extends ProtocolTerms[ScalaLanguage, Targ
typeName <- formatTypeName(name).map(formattedName => getClsName(name).append(formattedName))
tpe <- selectType(typeName)
maybeNestedDefinition <- processProperty(name, schema)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](Target.pure(tpe), schema, components)
resolvedType <- ModelResolver.propMetaWithName[ScalaLanguage, Target](() => Target.pure(tpe), schema, components)
prefixes <- vendorPrefixes()
propertyRequirement = getPropertyRequirement(schema, requiredFields.contains(name), defaultPropertyRequirement)
defValue <- defaultValue(typeName, schema, propertyRequirement, definitions)
Expand Down
8 changes: 1 addition & 7 deletions project/src/main/scala/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,19 @@ object Build {
def injectPRVersionPolicy(moduleSegment: String)(gitVersion: String): String = {
val labels = currentBuildLabels(moduleSegment)
val extractor = raw"^([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9]+-g[a-f0-9]+)?(-SNAPSHOT)?".r
println(s"injectPRVersionPolicy($moduleSegment)($gitVersion):")
val newVersion: String = gitVersion match {
case extractor(major, minor, patch, gitSlug, other) =>
if (labels.contains("major")) {
val newMajor = major.toInt + 1
println(s" major: ${major.toInt} -> ${newMajor}")
List(Some(s"${newMajor}.0.0"), Option(gitSlug), Option(other)).flatten.mkString("")
} else if (labels.contains("minor")) {
val newMinor = minor.toInt + 1
println(s" minor: ${minor.toInt} -> ${newMinor}")
List(Some(s"${major}.${newMinor}.0"), Option(gitSlug), Option(other)).flatten.mkString("")
} else {
val newPatch = patch.toInt + 1
println(s" patch: ${patch.toInt} -> ${newPatch}")
List(Some(s"${major}.${minor}.${newPatch}"), Option(gitSlug), Option(other)).flatten.mkString("")
}
case other =>
println(s" other: ${gitVersion}")
gitVersion
case other => gitVersion
}
newVersion
}
Expand Down
55 changes: 0 additions & 55 deletions support/apply-pr-label-locally.sh

This file was deleted.

0 comments on commit 3482f33

Please sign in to comment.