Skip to content

Implement Typed Documents and TypeRegistry #282

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 63 commits into
base: decaf
Choose a base branch
from
Open

Conversation

jterapin
Copy link
Contributor

@jterapin jterapin commented Mar 6, 2025

Description: Implementation for Typed Documents and TypeRegistry. Currently only supports JSON documents.

Customer Experience

Customer can instantiate a Document by using standard Ruby objects as its foundation:

string_doc = Smithy::Schema::Document.new('Hello World!')
string_doc.data
=> "Hello World!"

map_doc = Smithy::Schema::Document.new({ :name => 'Hamburger' })
map_doc.data
=> { "name" => "Hamburger" }

Customers can instantiate a Document with a runtime shape and its schema:

# given the following runtime shape:
typed_bird = BirdService::Types::Bird.new(name: 'Pidgey')
=> #<struct BirdService::Types::Bird name="Pidgey">

# provide runtime shape and its schema
bird_doc = Document.new(typed_bird, BirdService::Schema::Bird).data
=> { "name" => "Pidegey" }

When a runtime shape is used to create a Document, we capture the absolute shape id from its schema.

bird_doc.discriminator
=> "example.com#Bird"

Customers can reconstruct the runtime shape of a document by using as_typed method with a shape schema:

bird_doc.as_typed(BirdService::Schema::Bird)
=> #<struct BirdService::Types::Bird name="Pidgey">

Customers can use the TypeRegistry to find schema based on shape id:

BirdService::Schema::TypeRegistry.schema_by_id('somebird')
=> #<BirdService::Schema::Bird>

Remaining ToDos

  • Add RBS support for public interfaces ONLY
  • Add more Documentation (maybe)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jterapin jterapin changed the title Implement Typed Documents and TypeRegistry [WIP] Implement Typed Documents and TypeRegistry Mar 6, 2025
@jterapin jterapin changed the title [WIP] Implement Typed Documents and TypeRegistry Implement Typed Documents and TypeRegistry Apr 15, 2025
module Smithy
module Schema
# A Smithy document type, representing typed or untyped data from Smithy data model.
# ## Document types
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add more details (e.g. code examples) but I might punt that to the Smithy-Ruby Wiki instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in-code examples/documentation are preferred but it doesn't have to be done this moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea - I'd agree examples and more detail would be better as in code documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add them now - since information is very fresh in my head.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants