Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy for checking which fields were used for transformation #248

Open
MateuszKubuszok opened this issue Feb 11, 2023 · 3 comments
Open
Labels
enhancement help wanted relatively easy but not small Task with requires some knowlege and writing more code, but not the intimate knoledge about macros

Comments

@MateuszKubuszok
Copy link
Member

MateuszKubuszok commented Feb 11, 2023

Some users would find it useful to be able to fail compilation if some/all fields from source were not used during derivation. Example of such thing was asked in this StackOverflow question: https://stackoverflow.com/questions/73927120/chimeny-scala-validate-source .

Such feature was implemented in ducktape so alternative libraries already decided that it is worth providing.

We could consider adding some/all of the setting:

  • .requireSourceFieldsUsed
  • .requireSourceFieldsUsed(_.fieldA, _.fieldB, _.fieldC)
  • .requireSourceFieldsUsedExcept(_.fieldA, _.fieldB)
  • .requireTargetSubtypesUsed
  • .requireTargetSubtypeUsed[SubType]
  • .requireTargetSubtypeNotUsed[SubType]
@arainko
Copy link

arainko commented Feb 13, 2023

Just to clarify, the thing implemented in ducktape is only applicable to the Field.allMatching config option, where it'll fail to compile if you pass in a case class that matches none of the destination fields (but only for the case class passed to this config option) like this:

test("Field.allMatching reports a compiletime failure when none of the fields match") {
    final case class Source(int: Int, str: String, list: List[String])
    final case class FieldSource(int: Long, str: CharSequence, list: Vector[String])

    assertFailsToCompileWith {
      """
      val source = Source(1, "str", List("list-str"))
      val fieldSource = FieldSource(1L, "char-seq", Vector("vector-str"))
      source.into[Source].transform(Field.allMatching(fieldSource))
      """
    }("None of the fields from FieldSource match any of the fields from Source.")
  }

But it doesn't affect other parts of derivation, so you'd be the trailblazers here ❤️

@MateuszKubuszok
Copy link
Member Author

We could 😉 But it would be seriously helpful to know more about use cases of this feature. I saw some options named "policy" in Java's MapStruct but I have no idea what users could find useful, so any feedback about this is welcome!

For now we are mostly adding bugs and ideas to backlog to keep tabs on them, since we have a few things already planned (#239) and they will take some time 😄

@MateuszKubuszok MateuszKubuszok added the relatively easy but not small Task with requires some knowlege and writing more code, but not the intimate knoledge about macros label Oct 20, 2023
@MateuszKubuszok MateuszKubuszok added this to the Merge transformations milestone Dec 19, 2023
@SevDan
Copy link

SevDan commented Jan 14, 2024

There is a use case for policies in systems integrations with verbose and huge APIs (100-500 properties in single method/dto) when you want continuosly update their version in your application, such as legacy SOAP services. So, you can have compile time error for any unhandled changes with precise policy for the important parts and ignore unimportant ones. This is probably the main reason to use java's mapstruct in java or kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted relatively easy but not small Task with requires some knowlege and writing more code, but not the intimate knoledge about macros
Projects
None yet
Development

No branches or pull requests

3 participants