scala-jsonschema icon indicating copy to clipboard operation
scala-jsonschema copied to clipboard

Improve `None` for Optional Defaults Handling

Open andyglow opened this issue 3 years ago • 4 comments
trafficstars

  • [x] add tests
  • [ ] identify corner case from #241

andyglow avatar Feb 01 '22 18:02 andyglow

Codecov Report

Merging #251 (3156e6a) into master (f0f2085) will decrease coverage by 0.02%. The diff coverage is 76.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #251      +/-   ##
==========================================
- Coverage   76.16%   76.13%   -0.03%     
==========================================
  Files          65       65              
  Lines        1674     1777     +103     
  Branches       61       58       -3     
==========================================
+ Hits         1275     1353      +78     
- Misses        399      424      +25     
Impacted Files Coverage Δ
api/src/main/scala/json/Json.scala 0.00% <0.00%> (ø)
...thub/andyglow/json/LowPriorityArrayImplicits.scala 100.00% <ø> (ø)
...cala-2.13/com/github/andyglow/scalamigration.scala 50.00% <ø> (ø)
...n/scala/com/github/andyglow/json/ValueSchema.scala 70.00% <ø> (ø)
...in/scala/com/github/andyglow/json/comparison.scala 61.53% <0.00%> (+23.07%) :arrow_up:
...scala/com/github/andyglow/jsonschema/AsValue.scala 100.00% <ø> (ø)
...om/github/andyglow/jsonschema/AsValueBuilder.scala 100.00% <ø> (ø)
...scala/com/github/andyglow/jsonschema/package.scala 0.00% <0.00%> (ø)
core/src/main/scala/json/schema/Version.scala 80.00% <ø> (ø)
...cala/com/github/andyglow/jsonschema/Macroses.scala 70.00% <0.00%> (-7.78%) :arrow_down:
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 07582fa...3156e6a. Read the comment docs.

codecov-commenter avatar Feb 04 '22 06:02 codecov-commenter

@andyglow Sorry for the slow response. Been down with corona.

The corner I show cased in my ticket is only visible when I do .asCirce so I add to class AsCirceSpec:

  property("Check that Schema.asCirce translates default None") {
    import io.circe.generic.auto._
    import json.schema.Version.Draft07
    import AsCirce._
    import com.github.andyglow.jsonschema.WrappingObject.NoneForDefaultModelsCase4

    json.Json
      .schema[List[NoneForDefaultModelsCase4]]
      .asCirce(Draft07(id = ""))
      .toString().replaceAll("\\s", "")  shouldBe """"""
  }

and even then I seems to only happen when the case classes are wrapped in an object like:

object WrappingObject {
  case class NoneForDefaultModelsCase4Inner(name: String, innerLevel2: Option[String] = None)

  case class NoneForDefaultModelsCase4(name: String, inner: Option[NoneForDefaultModelsCase4Inner] = None)
}

I am not allowed to push to the PR to demo.

bjornbak avatar Feb 09 '22 06:02 bjornbak

I have the same issue (related to .asCirce)

and even then it seems to only happen when the case classes are wrapped in an object like

and it is reproducible even for the case of definition a case class on the root level without wrapping object

@ConfiguredJsonCodec
case class ExtractRule(
  rule: CommonExtractRule,
  defaults: Option[UriDefaults] = None
) extends UriRule

@ConfiguredJsonCodec
case class UriDefaults(
  host: Option[String] = None,
  port: Option[Int] = None,
  scheme: String = "https"
)

oleksandr-balyshyn avatar Mar 09 '22 22:03 oleksandr-balyshyn

@oleksandr-balyshyn Did you find a solution or workaround?

bjornbak avatar Mar 10 '23 04:03 bjornbak