-
Notifications
You must be signed in to change notification settings - Fork 422
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
add discriminatorMapping when deriving a schema for co-products #1838
add discriminatorMapping when deriving a schema for co-products #1838
Conversation
Could you make a PR against |
|
||
final case class Configuration(toEncodedName: String => String, discriminator: Option[String]) { | ||
final case class Configuration(toEncodedName: String => String, discriminator: Option[String], toEncodedSubtypeName: TypeName => String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we'd need to avoid depending on magnolia's class, as this is kind of an implementation detail. Maybe it would make sense to use SName => String
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely! Also this is probably the reason CI failed here.
@@ -244,7 +244,15 @@ class SchemaGenericAutoTest extends AsyncFlatSpec with Matchers { | |||
) | |||
) | |||
|
|||
schemaType.asInstanceOf[SCoproduct[Entity]].discriminator shouldBe Some(SDiscriminator(FieldName("who_am_i"), Map.empty)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be great to add a test with non-identity subtype name transformations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
Sure! (I was secretly hoping for this to make into 0.19.x :) but we can wait for 0.20.x) |
@yurique since this is binary incompatible, 0.20 is a better target :) |
Totally makes sense :) |
833f43f
to
0a8962e
Compare
This now targets
|
Not sure why CI is not kicking in. |
Thanks! Two more things:
|
(no idea why CI didn't run) |
* rename toEncodedSubtypeName -> toDiscriminatorValue
I like it. Done.
Done. btw, what's the role of |
Thanks! :) |
SchemaMacros are version-specific extensions for |
Without
discriminatorMapping
the OpenAPI generator can't make sense of the schema and fails.I'm not sure if adding fields to
Configuration
was a right call – this breaks bin-compat, but I can re-work things here to re-usetoEncodedName
(and deal with the$
suffix on the call site).