From fd7ad9a7a78ca2dd525c706d9aa38dfd1d872cdf Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sat, 23 Dec 2023 13:24:30 -0800 Subject: [PATCH 1/3] Removing verbose version bumping logic --- project/src/main/scala/Build.scala | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/project/src/main/scala/Build.scala b/project/src/main/scala/Build.scala index c13b5e22f..1e9eb6ef0 100644 --- a/project/src/main/scala/Build.scala +++ b/project/src/main/scala/Build.scala @@ -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 } From 14d2a48ddf5fd993ba3013fb45bd40e196b09171 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sat, 23 Dec 2023 13:27:58 -0800 Subject: [PATCH 2/3] Removing deprecated support script --- support/apply-pr-label-locally.sh | 55 ------------------------------- 1 file changed, 55 deletions(-) delete mode 100755 support/apply-pr-label-locally.sh diff --git a/support/apply-pr-label-locally.sh b/support/apply-pr-label-locally.sh deleted file mode 100755 index 6187115d5..000000000 --- a/support/apply-pr-label-locally.sh +++ /dev/null @@ -1,55 +0,0 @@ -exit 0 - -pr_number="$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")" -labels=( - $(curl \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - "https://api.github.com/repos/guardrail-dev/guardrail/pulls/${pr_number}" | \ - jq -r '.labels | map(.name)[]' - ) -) - -bump= -major= -minor= -patch=1 - -for label in "${labels[@]}"; do - if [ "$label" = major ]; then - bump=1 - major=1 - elif [ "$label" = minor ]; then - bump=1 - minor=1 - elif [ "$label" = patch ]; then - bump=1 - patch=1 - fi -done - -echo "Bump: major=${major} minor=${minor} patch=${patch} bump=${bump}" - -if [ -n "$bump" ]; then - - modules=( cli core guardrail java-async-http java-dropwizard java-spring-mvc java-support scala-akka-http scala-dropwizard scala-http4s scala-support ) - - for module in "${modules[@]}"; do - previous="$(git tag --sort=-taggerdate | grep "$(printf '^%s-v' "$module")" | tail -n 1)" - last="$(echo "$previous" | sed "s/^${module}-v\\([0-9.]*\\)$/\\1/")" - parts=( ${last//./ } ) - - if [ -n "$major" ]; then - parts=( $((parts[0]+1)) 0 0 ) - elif [ -n "$minor" ]; then - parts=( ${parts[0]} $((parts[1]+1)) 0 ) - elif [ -n "$patch" ]; then - parts=( ${parts[0]} ${parts[1]} $((parts[2]+1)) ) - fi - - next="${parts[0]}.${parts[1]}.${parts[2]}" - - echo "$last -> $next" - git tag "${module}-v${next}" - done -fi From 19d1d9c87b09fd41ac3365d1a728367dfcdded4c Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sat, 23 Dec 2023 14:42:39 -0800 Subject: [PATCH 3/3] Target is more strict than I thought --- .../dev/guardrail/core/resolvers/ModelResolver.scala | 8 ++++---- .../generators/java/jackson/JacksonGenerator.scala | 2 +- .../src/test/scala/core/issues/Issue195.scala | 4 ++-- modules/sample/src/main/resources/issues/issue195.yaml | 6 +++++- .../generators/scala/circe/CirceProtocolGenerator.scala | 6 +++--- .../scala/circe/CirceRefinedProtocolGenerator.scala | 6 +++--- .../scala/jackson/JacksonProtocolGenerator.scala | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/core/src/main/scala/dev/guardrail/core/resolvers/ModelResolver.scala b/modules/core/src/main/scala/dev/guardrail/core/resolvers/ModelResolver.scala index 927c4d405..44792b4ae 100644 --- a/modules/core/src/main/scala/dev/guardrail/core/resolvers/ModelResolver.scala +++ b/modules/core/src/main/scala/dev/guardrail/core/resolvers/ModelResolver.scala @@ -40,7 +40,7 @@ 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], @@ -48,10 +48,10 @@ object ModelResolver { ): 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], *]])) ) diff --git a/modules/java-support/src/main/scala/dev/guardrail/generators/java/jackson/JacksonGenerator.scala b/modules/java-support/src/main/scala/dev/guardrail/generators/java/jackson/JacksonGenerator.scala index 262a1f000..ae0554d08 100644 --- a/modules/java-support/src/main/scala/dev/guardrail/generators/java/jackson/JacksonGenerator.scala +++ b/modules/java-support/src/main/scala/dev/guardrail/generators/java/jackson/JacksonGenerator.scala @@ -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) diff --git a/modules/sample-akkaHttp/src/test/scala/core/issues/Issue195.scala b/modules/sample-akkaHttp/src/test/scala/core/issues/Issue195.scala index 6bdf4f991..e88ee5282 100644 --- a/modules/sample-akkaHttp/src/test/scala/core/issues/Issue195.scala +++ b/modules/sample-akkaHttp/src/test/scala/core/issues/Issue195.scala @@ -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"))) } } diff --git a/modules/sample/src/main/resources/issues/issue195.yaml b/modules/sample/src/main/resources/issues/issue195.yaml index 2845fe56c..ba4d4b738 100644 --- a/modules/sample/src/main/resources/issues/issue195.yaml +++ b/modules/sample/src/main/resources/issues/issue195.yaml @@ -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: diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceProtocolGenerator.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceProtocolGenerator.scala index 3106dbed4..0abb51b9e 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceProtocolGenerator.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceProtocolGenerator.scala @@ -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")), @@ -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) diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala index cb91a07ae..0069209b2 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala @@ -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")), @@ -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) diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala index 32a0cca66..e5cda79c2 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala @@ -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)