-
Notifications
You must be signed in to change notification settings - Fork 7
Implement Typed Documents and TypeRegistry #282
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
Conversation
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.
Nice. Looking better. Still have a bunch of comments though .. In general I think we can still simplify and also be less aggressive on validation and instead be more permissive where possible.
# shape = Smithy::Schema::StructureShape.new | ||
# data = Document::Data.new({ "name" => "example" }, shape: shape) | ||
# | ||
module Document |
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 was expecting document to be a class and have it be the delegator. What was the intention of making another data subclass?
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.
From what I recall - I believe I wanted to the Document (De)serializers to be nested under the Document namespace.
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.
Reverted back to Document class approach with some class methods.
describe Serializer do | ||
let(:shapes) do | ||
shapes = SchemaHelper.sample_shapes | ||
shapes['smithy.ruby.tests#Structure']['members']['timestampDateTime'] = { |
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 would prefer if you move these definitions closer to the test (in the actual tests where they are needed) - it's easier to manage tests that way if they are discrete.
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.
That's fair - I'll move it.
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.
Nice - its generally looking good.
I think the functionality from the Document::Data class could be moved into Document
as a class (unless theres some reason I'm missing). I also understand why the Document serializer and deserializer exist separately and require a type registery - but I think I would lean towards the public interface for serializing/deserializing documents living on the top level class - it could still require a type registry to be provided and could use these classes under the hood to implement it (and they could then be api private).
That's effectively what I was also saying but I agree. |
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 tried to look over every comment that I wrote (since I like to write it as I go to remember where I left off) so if something doesn't make sense, let me know! Thanks!
# shape = Smithy::Schema::StructureShape.new | ||
# data = Document::Data.new({ "name" => "example" }, shape: shape) | ||
# | ||
module Document |
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.
From what I recall - I believe I wanted to the Document (De)serializers to be nested under the Document namespace.
module Schema | ||
module Document | ||
# Serializes data into a document data. | ||
class Serializer |
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.
Yeah... Ideally, I would like that but for typed documents to work properly (deserializing nested typed documents) - it needs to reference a specific type_registry
to (de)serialize properly.
This is prob why Dowling wanted TypeRegistry to handle these responsibilities.
# # => an instance of Smithy::Schema::Document::Data | ||
# document.discriminator | ||
# # => "smithy.ruby.tests#Structure" | ||
def create_document(data) |
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 could create a class method under Document that references this file to handle (under the hood).
# @option opts [Boolean] :use_json_name Whether to use `jsonName` trait | ||
# or just member name. The `jsonName` trait is ignored by default. | ||
# @return [Hash] Serialized document data | ||
def serialize_document(document, opts = {}) |
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.
Yeah I can make class methods at the Document level
# TODO: failing due to synthetic shape changes | ||
# it 'contains a registry of typed shapes' do | ||
# expect(subject.keys).to match_array(typed_shapes.keys) | ||
# end |
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.
Commented out failing test due to synthetic input/output shape id changes
|
||
class << self | ||
def type_registry | ||
Smithy::Schema::TypeRegistry.new([CityCoordinates, CitySummary, GetCityInput, GetCityOutput, GetCurrentTimeOutput, GetForecastInput, GetForecastOutput, ListCitiesInput, ListCitiesOutput, NoSuchResource]) |
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.
Could go back to doing map, etc but this will increase file size for services like ec2
Description: Implementation for Typed Documents and TypeRegistry. Currently only supports JSON documents.
It is highly likely that we have to revisit this implementation in the future since typed document/type registry still being evolved.