Allow optional output schema fields#151
Merged
Merged
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019df784-c259-7229-b13f-21c1ec2c2c1a Co-authored-by: Amp <amp@ampcode.com>
22424b9 to
c4025e7
Compare
juliavallina
approved these changes
May 14, 2026
Contributor
juliavallina
left a comment
There was a problem hiding this comment.
Tested and working as expected.
I bumped the version to generate a new release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #147.
.optional()to Tinybird type validators so endpoint output fields can be marked as absent from some responses without changing their Tinybird/ClickHouse type.InferOutputandInferOutputRowso optional output validators become optional object properties.Documentation / changelog note
Endpoint output schemas now support optional fields for templated responses where a column may or may not be selected depending on request params. The SDK does not generate the template condition automatically;
.optional()documents and types the response contract so schema validation accepts both shapes.Example:
This infers:
How to test
Run with Node 20 via nvm:
Manual reviewer check
Create an endpoint output schema with optional fields backed by templated SQL as above.
Both rows should type-check:
Live Tinybird validation
Validated against Tinybird Cloud workspace
gnzoptionalsdkwith deployed resources:sdk_optional_output_eventssdk_optional_output_endpointThe endpoint was deployed with a templated
include_debugparam and queried both ways.include_debug: "0"response shape:{ "keys": ["event_count", "event_name"], "has_debug_info": false, "has_nullable_debug_info": false }include_debug: "1"response shape:{ "keys": ["debug_info", "event_count", "event_name", "nullable_debug_info"], "has_debug_info": true, "has_nullable_debug_info": true }Additional regression covered
After testing an upgrade scenario, we also verified that param metadata/default rewriting is only applied to Tinybird typed parameter template functions (
String,DateTime,Int32, etc.). Non-param helper functions such assplit_to_array(...)andcolumn(...)must be preserved as-is because Tinybird rejects generated keywords likerequired=Falseordescription=...for those helpers.Regression example:
Expected generated SQL keeps the helper unchanged:
{{ split_to_array(siteIds) }}