Add cmdio.RenderFiltered to strip fields from rendered output#5450
Open
Divyansh-db wants to merge 2 commits into
Open
Add cmdio.RenderFiltered to strip fields from rendered output#5450Divyansh-db wants to merge 2 commits into
Divyansh-db wants to merge 2 commits into
Conversation
Adds new cmdio.RenderFiltered and cmdio.RenderIteratorFiltered entry points that mirror Render / RenderIterator but accept a list of dotted JSON paths to strip from the value before it is marshaled. The list is consulted only on the JSON render path; text/template rendering is unchanged. Motivation: the Databricks SDK uses a single transport struct per resource for both request and response. Some fields are required on the request side (so the SDK marshals them unconditionally) but input-only on the response side per the OpenAPI spec. The CLI today hands the SDK response struct directly to json.MarshalIndent, so those fields leak into user-visible output even though the server doesn't populate them. RenderFiltered gives generated CLI commands a way to strip such fields without modifying the SDK or introducing a separate view layer. Nothing in the generated CLI surface calls these new entry points yet; that switch will land alongside the corresponding codegen change. Co-authored-by: Isaac
Contributor
Waiting for approvalBased on git history, these people are best suited to review:
Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
Collaborator
|
Commit: e3d5421 |
deletePath was traversing arrays transparently but not maps. When the generator emits a path like "tags.initial_workspace_id" for a map[string]V field whose value type has an INPUT_ONLY field, the literal "initial_workspace_id" key doesn't exist directly under "tags" — it lives inside each map value — so the path was silently a no-op at render time. Mirror the array behavior: when a path component doesn't match a literal key on the current object, descend into every value with the same key list. The literal-match path is still preferred, so struct field paths keep working unchanged. Adds two tests: a top-level map field and a map nested inside another struct, both checking that the inner field is stripped from every value. Co-authored-by: Isaac
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
Adds new
cmdio.RenderFilteredandcmdio.RenderIteratorFilteredentry points that mirrorRender/RenderIteratorbut accept a[]stringof dotted JSON paths to strip from the value before it is marshaled. The path list is consulted only by the JSON render path; text/template rendering is unchanged.Path syntax is dotted (
a.b.c); arrays are traversed transparently, so the same path expression works for singleton and list responses without anitems[]marker.Motivation
The Databricks SDK uses a single Go struct per resource for both request and response (transport-layer pattern). Some fields are
REQUIREDon the request side, so the SDK marshals them unconditionally, while also beingINPUT_ONLYper the OpenAPI spec — they're never populated on responses. Generated CLI commands hand the SDK response struct directly tojson.MarshalIndent, so those fields leak into user-visible output as empty strings even when the server omits them.Existing in-repo precedents for honoring
x-databricks-field-behaviors:bundle/direct/tools/generate_resources.pyreadsINPUT_ONLY/OUTPUT_ONLYfrom the OpenAPI spec and propagates them into the DABs direct engine'signore_remote_changesconfig.bundle/internal/schema/main.go'sremoveOutputOnlyFieldsstripsOUTPUT_ONLYfrom the bundle JSON schema.RenderFilteredis the equivalent seam on the CLI response render path. This PR adds only the entry points; the genkit template change that starts calling them will land separately, followed by the generated-code regeneration incmd/account/**andcmd/workspace/**.Design notes
Renderis unchanged in behavior (now a thin wrapper aroundRenderFiltered(_, _, nil)). Existing callers don't need to change.applyInputOnlyMaskinlibs/cmdio/filter.goround-trips the value throughjson.Marshalinto a genericmap[string]anytree, removes the listed leaf keys, and returns the masked value for the caller to marshal in its preferred format. Operating on the generic tree (rather than on raw bytes) letsdefaultRenderer.renderJsonanditeratorRenderer.renderJsonreuse the same masking logic despite using differentMarshalIndentprefixes.colorizeJSON, so the colorized output stays consistent.Test plan
go test ./libs/cmdio/...— pass (new and existing tests)gofmt -lclean on changed files;go vet ./libs/cmdio/...clean./task fmt-q/./task lint-q— 0 issuesRenderFilteredmatches plainRenderwhen no paths are supplied.