-
Notifications
You must be signed in to change notification settings - Fork 71
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
Support unknown field retention trait #1409
base: series/0.18
Are you sure you want to change the base?
Conversation
0e907a9
to
485a43a
Compare
a7de7a5
to
6728eb9
Compare
8f48bc4
to
44b76f3
Compare
44b76f3
to
0430424
Compare
field.hints.get(JsonName) match { | ||
case None => field.label | ||
case Some(x) => x.value | ||
} | ||
|
||
trait UnknownFieldsDecoder[A] { self => |
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.
rather than creating a bespoke trait (which implies having to create a schema visitor for it), I'd just delegate to Document.Decoder
, turning the Hashmap
into a Document.DObject
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.
Done in 59e0d22.
@@ -1299,35 +1336,81 @@ private[smithy4s] class SchemaVisitorJCodec( | |||
) | |||
} | |||
|
|||
trait UnknownFieldsEncoder[A] { |
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.
Rather than creating a bespoke trait, I'd delegate to the Document.Encoder
to produce a document representation. I'd then match the document to check if it's a DObject and would call upon a function to inline its fields, that I'd factor out of the encoder implementation for documents.
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.
Done in 59e0d22. Wasn't sure what you meant by this:
I'd factor out of the encoder implementation for documents
I think you're referring to this:
case Document.DObject(values) =>
values.foreach { case (key, value) =>
out.writeKey(key)
documentJCodec.encodeValue(value, out)
}
but it seems too small to be worth factoring out to me - can you confirm?
@@ -181,6 +182,42 @@ class DocumentEncoderSchemaVisitor( | |||
from(e => DString(total(e).stringValue)) | |||
} | |||
|
|||
trait UnknownFieldsEncoder[A] { |
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.
No need for a bespoke trait : just compile the DocumentEncoder for A
, and inline its fields if the result is a DObject
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.
Done in 59e0d22.
@@ -451,16 +506,16 @@ class DocumentDecoderSchemaVisitor( | |||
alternatives: Vector[Alt[U, _]], | |||
dispatch: Alt.Dispatcher[U] | |||
): DocumentDecoder[U] = { | |||
def jsonLabel[A](alt: Alt[U, A]): String = | |||
def jsonLabelOrLabel[A](alt: Alt[U, A]): 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 mean ... why ?
val unknownFieldsDecoder = UnknownFieldsDecoder(field.schema) | ||
( | ||
pp: List[PayloadPath.Segment], | ||
buffer: Any => Unit, | ||
fields: Map[String, Document] | ||
) => { | ||
val unknownFields = fields -- knownFieldLabels | ||
buffer(unknownFieldsDecoder(pp, unknownFields)) | ||
} |
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'd like this bit to be extracted in a private method.
@@ -307,66 +308,120 @@ class DocumentDecoderSchemaVisitor( | |||
} | |||
} | |||
|
|||
trait UnknownFieldsDecoder[A] { self => |
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.
This one could be removed too : just compile the document decoder for A
and pass it a DObject
containing the unknownFields
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.
Done in 59e0d22.
3942bb2
to
59e0d22
Compare
fields.foreach { case (field, jsonLabel, default) => | ||
values += { | ||
if (isForUnknownFieldRetention(field)) { | ||
// TODO: Lift out. |
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.
Currently working on a refactor to avoid re-creating this decoder on each call. Will move on to the remaining feedback actions once I've done this.
Please refrain from force-pushing once you've opened a PR. It prevents the review of the latest changes, and also makes it extremely annoying if someone was branching out from your work to help out or not. We tend to squash PRs anyway at the end. |
I thought you were OK with it so long as the change is in draft state, not PR. I wouldn't have done it it with PRs. I'll try to remember not to with drafts now, apologies if I forget occasionally while I adjust. |
It's not about whether it's a draft or not. I switch to not being OK with it at the point when you ask me to have a look at it. Generally speaking I'll avoid looking at drafts unless asked to, but once you ask, you're essentially opening the Schrödinger box. |
Ok yeah I get that. |
PR Checklist (not all items are relevant to all PRs)