René's URL Explorer Experiment


Title: Feature Proposal: Opt-in Sorbet `T::Struct` Generation from Schema Components · Issue #61 · openapi-ruby/openapi-ruby · GitHub

Open Graph Title: Feature Proposal: Opt-in Sorbet `T::Struct` Generation from Schema Components · Issue #61 · openapi-ruby/openapi-ruby

X Title: Feature Proposal: Opt-in Sorbet `T::Struct` Generation from Schema Components · Issue #61 · openapi-ruby/openapi-ruby

Description: Problem Schema components defined with OpenapiRuby::Components::Base are documentation-only at runtime. Projects using Sorbet for type checking face a duplication problem: every request/response schema that needs typed access in applicat...

Open Graph Description: Problem Schema components defined with OpenapiRuby::Components::Base are documentation-only at runtime. Projects using Sorbet for type checking face a duplication problem: every request/response sc...

X Description: Problem Schema components defined with OpenapiRuby::Components::Base are documentation-only at runtime. Projects using Sorbet for type checking face a duplication problem: every request/response sc...

Opengraph URL: https://github.com/openapi-ruby/openapi-ruby/issues/61

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Proposal: Opt-in Sorbet `T::Struct` Generation from Schema Components","articleBody":"## Problem\n\nSchema components defined with `OpenapiRuby::Components::Base` are documentation-only at runtime. Projects using [Sorbet](https://sorbet.org/) for type checking face a duplication problem: every request/response schema that needs typed access in application code must be redefined as a separate `T::Struct`, keeping two sources of truth in sync manually.\n\nThe gem already bridges this gap for strong params — `permitted_params` reads the `schema()` DSL and derives a permit list. The same approach could eliminate the parallel `T::Struct` boilerplate.\n\n## Proposed Solution\n\nAn opt-in mixin (e.g. `OpenapiRuby::Components::TypedParams`) that reads the parsed `schema(...)` definition and auto-generates `T::Struct` `const` declarations on the including class. Schema components that include this mixin serve double duty: OpenAPI docs **and** a typed runtime struct.\n\n### Example usage\n\n```ruby\nclass Schemas::UserInput\n  include OpenapiRuby::Components::Base\n  include OpenapiRuby::Components::TypedParams  # opt-in\n\n  schema(\n    type: :object,\n    required: %w[name email],\n    properties: {\n      name:  { type: :string },\n      email: { type: :string },\n      bio:   { type: :string, nullable: true }\n    }\n  )\nend\n\n# After including TypedParams, the class behaves as a T::Struct:\nuser = Schemas::UserInput.new(name: \"Jane\", email: \"jane@example.com\")\nuser.name  # => \"Jane\"  (typed as String)\nuser.bio   # => nil      (typed as T.nilable(String))\n```\n\n## Implementation Sketch\n\n### 1. Type mapping\n\nOpenAPI type → Sorbet type:\n\n| OpenAPI | Sorbet |\n| --- | --- |\n| `string` | `String` |\n| `integer` | `Integer` |\n| `number` | `Float` |\n| `boolean` | `T::Boolean` |\n| `array` with `items` | `T::Array[\u003citem type>]` |\n| `object` (nested) | resolved Ruby class if `$ref`, or `T::Hash[String, T.untyped]` |\n| `$ref` to another component | the referenced Ruby class |\n| `nullable: true` or not in `required` | `T.nilable(...)` |\n\n### 2. `$ref` resolution\n\nRefs like `\"#/components/schemas/UserInput\"` would resolve to the corresponding Ruby class (e.g. `Schemas::UserInput`) by stripping the path prefix and calling `Object.const_get`. Referenced schemas would also need to include `TypedParams` to be instantiable as structs.\n\n### 3. Struct generation\n\nThe mixin uses `const` (immutable) declarations, matching the read-only nature of request params:\n\n```ruby\n# auto-generated equivalent of the schema above:\nconst :name, String\nconst :email, String\nconst :bio, T.nilable(String)\n```\n\n### 4. Tapioca DSL compiler\n\nSince Sorbet cannot see metaprogrammed `const` declarations, a companion [Tapioca](https://github.com/Shopify/tapioca) DSL compiler would emit RBI files for all schema classes that include `TypedParams`:\n\n```bash\nbin/tapioca dsl Schemas::UserInput\n```\n\n## Packaging\n\nSorbet must **not** become a dependency of `openapi-ruby` itself — this feature is strictly opt-in for teams that already use Sorbet. Two packaging options:\n\n- **Optional require path** — ship the mixin inside the gem behind `require \"openapi_ruby/sorbet\"`, which raises a clear error if `sorbet-runtime` is not installed. Zero impact on projects that never require it.\n- **Companion gem** — a separate `openapi-ruby-sorbet` gem that declares `sorbet-runtime` as its own dependency. Cleaner dependency boundary, but one more gem to manage.\n\n## Design Questions\n\n1. **Inheritance model** — Should `TypedParams` make the class inherit from `T::Struct` automatically, or require the user to set up inheritance explicitly? Auto-inheriting is more ergonomic but changes the class hierarchy.\n2. **Enum constraints** — Should enum values be validated on struct construction, or is that left to the runtime validation middleware?\n3. **Nested arrays of `$ref`** — e.g. `type: :array, items: { \"$ref\" => \"...\" }` — should element types resolve through the same ref-resolution path?\n4. **Optional require vs. companion gem** — Which packaging approach is preferred? (Either way, Sorbet remains a user-side opt-in, never a transitive dependency of `openapi-ruby`.)\n\n## Prior Art\n\n- `permitted_params` already reads `schema()` and generates runtime artifacts (strong params permit lists), establishing this pattern within the gem\n- [Sorbet's `T::Struct`](https://sorbet.org/docs/tstruct) for typed value objects\n- [Tapioca DSL compilers](https://github.com/Shopify/tapioca#writing-custom-dsl-compilers) for making metaprogrammed methods visible to Sorbet","author":{"url":"https://github.com/marshallshen","@type":"Person","name":"marshallshen"},"datePublished":"2026-10-29T20:41:24Z","url":"https://github.com/openapi-ruby/openapi-ruby/issues/61"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a877ae24-c41a-4ee2-56a5-7d71de99c04e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9D8A:2DBB21:170B418:1EAE823:6B0142E6
html-safe-nonce1a82e1ffb2c0f0b79c9eab2e6d49cdd5bf9f4f1a4095338a603545f11a640e57
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDhBOjJEQkIyMToxNzBCNDE4OjFFQUU4MjM6NkIwMTQyRTYiLCJ2aXNpdG9yX2lkIjoiNTc0MTkwMzkxNTM4NTk2MzIzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccee8cf8b89aaf51e4d8ce8628f3876c50396c5baf5122de4b315fd4d0af5bf26
hovercard-subject-tagissue:6108114535
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openapi-ruby/openapi-ruby/61/issue_layout
twitter:imagehttps://opengraph.githubassets.com/15384d6b22483c5858af7ef31cdc4895296abbb0965916267e638c151f148566/openapi-ruby/openapi-ruby/issues/61
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/15384d6b22483c5858af7ef31cdc4895296abbb0965916267e638c151f148566/openapi-ruby/openapi-ruby/issues/61
og:image:altProblem Schema components defined with OpenapiRuby::Components::Base are documentation-only at runtime. Projects using Sorbet for type checking face a duplication problem: every request/response sc...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemarshallshen
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/openapi-ruby/openapi-ruby git https://github.com/openapi-ruby/openapi-ruby.git
octolytics-dimension-user_id276587259
octolytics-dimension-user_loginopenapi-ruby
octolytics-dimension-repository_id1211860664
octolytics-dimension-repository_nwoopenapi-ruby/openapi-ruby
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1211860664
octolytics-dimension-repository_network_root_nwoopenapi-ruby/openapi-ruby
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/openapi-ruby/openapi-ruby/issues/61#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenapi-ruby%2Fopenapi-ruby%2Fissues%2F61
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenapi-ruby%2Fopenapi-ruby%2Fissues%2F61
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=openapi-ruby%2Fopenapi-ruby
Reloadhttps://github.com/openapi-ruby/openapi-ruby/issues/61
Reloadhttps://github.com/openapi-ruby/openapi-ruby/issues/61
Reloadhttps://github.com/openapi-ruby/openapi-ruby/issues/61
openapi-rubyhttps://github.com/openapi-ruby
openapi-rubyhttps://github.com/openapi-ruby/openapi-ruby
Codehttps://github.com/openapi-ruby/openapi-ruby
Issues1 (1)https://github.com/openapi-ruby/openapi-ruby/issues
Pull requests2 (2)https://github.com/openapi-ruby/openapi-ruby/pulls
Actionshttps://github.com/openapi-ruby/openapi-ruby/actions
Projectshttps://github.com/openapi-ruby/openapi-ruby/projects
Security and qualityhttps://github.com/openapi-ruby/openapi-ruby/security
Insightshttps://github.com/openapi-ruby/openapi-ruby/insights
https://github.com/openapi-ruby/openapi-ruby
New issuehttps://github.com/login?return_to=https://github.com/openapi-ruby/openapi-ruby/issues/61
New issuehttps://github.com/login?return_to=https://github.com/openapi-ruby/openapi-ruby/issues/61
Feature Proposal: Opt-in Sorbet T::Struct Generation from Schema Componentshttps://github.com/openapi-ruby/openapi-ruby/issues/61#top
https://github.com/marshallshen
marshallshenhttps://github.com/marshallshen
on Oct 29, 2026https://github.com/openapi-ruby/openapi-ruby/issues/61#issue-6108114535
Sorbethttps://sorbet.org/
Tapiocahttps://github.com/Shopify/tapioca
Sorbet's T::Structhttps://sorbet.org/docs/tstruct
Tapioca DSL compilershttps://github.com/Shopify/tapioca#writing-custom-dsl-compilers
Sign up for freehttps://github.com/signup?return_to=https://github.com/openapi-ruby/openapi-ruby/issues/61
Sign in to commenthttps://github.com/login?return_to=https://github.com/openapi-ruby/openapi-ruby/issues/61
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.