Add support for play 2.9 / scala 3 generators #696
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Play 2.9 supports Scala3. This change provides a new generator to support scala3.
If you would like to use the Scala3 code generator, use the
play_2_9_scala_3_client
ofplay_2_x_scala_3_json
generators. Example diff of apibuilder/config:The main change in the generator is to refactor the play json readers/writers for union types. The main difference in scala3 is how the types are resolved which is a bit stricter in resolving parent types and in finding potential duplicate implicits.
Our approach here is to remove implicit readers/writers for models that are part of a union type and to refactor the union type readers/writers so that they can apply universally to models.
We also have a gap with identifying union readers for collections - in this PR we add support to explicitly serialize/deserialize
Seq[T]
where T is a union type - but over time would like to explore more complete solutions.There is one change in readers that we applied to both scala2 and scala3. Rather than relying on implicits when deserializing an instance of a union type to a JS Object, we now explicitly invoke the correct underlying method after we match on discriminator. Example:
Old:
New:
This change is expected and tested to be fully backwards compatible.