Skip to content

feat(wren): add wren docs connection-info CLI command#1507

Merged
douenergy merged 5 commits intomainfrom
feat/cli-docs-command
Apr 2, 2026
Merged

feat(wren): add wren docs connection-info CLI command#1507
douenergy merged 5 commits intomainfrom
feat/cli-docs-command

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Apr 2, 2026

Summary

  • Add wren docs connection-info subcommand that generates documentation for all data source connection info fields directly from Pydantic models
  • Supports --format md (Markdown table with field type, required, default, sensitive, alias, example) and --format json (JSON Schema)
  • Add --envelope flag to output JSON in {"datasource": ..., "properties": ...} envelope format matching the MCP web UI convention
  • Filterable by data source name: wren docs connection-info postgres

Usage

wren docs connection-info                          # all sources, Markdown
wren docs connection-info postgres                 # single source
wren docs connection-info -f json                  # JSON Schema
wren docs connection-info duckdb -f json --envelope # envelope format

Test plan

  • Verified wren docs connection-info outputs all data sources in Markdown
  • Verified single data source filter works (postgres, bigquery, duckdb)
  • Verified --format json outputs valid JSON Schema
  • Verified --envelope produces {"datasource": ..., "properties": ...} format
  • Verified discriminated unions (bigquery, redshift, databricks) show all variants
  • just lint passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new CLI "docs" command group with a connection-info command to show connection configuration details.
    • connection-info [datasource] outputs documentation in Markdown or JSON (default: Markdown).
    • Markdown output includes per-datasource sections, model tables, field metadata, sensitivity flags, aliases, defaults and example blocks.
    • JSON output supports a compact schema or an alternate "envelope" shape via --envelope.
    • Unknown/unsupported datasources or formats produce a clear error and exit non-zero.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c5838dff-9b5d-4708-880b-8cdae1bc4c01

📥 Commits

Reviewing files that changed from the base of the PR and between 74edefa and 62cf212.

📒 Files selected for processing (1)
  • wren/src/wren/docs.py
✅ Files skipped from review due to trivial changes (1)
  • wren/src/wren/docs.py

📝 Walkthrough

Walkthrough

Adds a new docs CLI subcommand and a wren.docs module to generate Markdown or JSON schema documentation for Pydantic BaseConnectionInfo models; supports optional JSON envelope, normalizes --format, and exits with status 1 on unsupported formats or resolution errors.

Changes

Cohort / File(s) Summary
CLI Integration
wren/src/wren/cli.py
Added docs Typer app and connection-info command (datasource positional, --format/-f, --envelope). Normalizes format, dynamically imports wren.docs, dispatches to markdown or JSON generators, forwards --envelope only for JSON, and exits with status 1 on unsupported formats or ValueError.
Documentation Generation Module
wren/src/wren/docs.py
New module exporting DATASOURCE_MODELS, generate_markdown(), and generate_json_schema(). Resolves datasource(s), introspects Pydantic BaseConnectionInfo models (including union/variant lists), detects sensitive fields, formats types/defaults/examples, escapes Markdown cells, and emits raw or enveloped JSON structures; raises ValueError for unknown datasources.

Sequence Diagram(s)

sequenceDiagram
    participant User as "User"
    participant CLI as "CLI\n(docs connection-info)"
    participant Docs as "wren.docs\n(generators)"
    participant Models as "Pydantic\nBaseConnectionInfo models"

    User->>CLI: run docs connection-info [datasource] --format md/json --envelope?
    CLI->>CLI: normalize format
    alt format == "md"
        CLI->>Docs: generate_markdown(datasource)
        Docs->>Models: inspect models, fields, types, defaults, examples
        Models-->>Docs: metadata
        Docs-->>CLI: markdown string
    else format == "json"
        CLI->>Docs: generate_json_schema(datasource, envelope)
        Docs->>Models: inspect models/schemas/examples
        Models-->>Docs: schemas/examples
        Docs-->>CLI: json string (optionally envelope)
    else unsupported
        CLI-->>User: stderr error + exit 1
    end
    CLI-->>User: print output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

documentation

Suggested reviewers

  • douenergy

Poem

🐰 I hopped through fields and found bright trails,
I nibbled types, munched defaults and details,
Markdown carrots, JSON berries in view,
I stitched each schema with a tiny shoe,
Docs stitched neat — a rabbit’s joyful cue.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new wren docs connection-info CLI command, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cli-docs-command

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

goldmedal and others added 2 commits April 2, 2026 10:46
Generate documentation for all data source connection info fields
directly from Pydantic models. Supports Markdown and JSON Schema
output formats, with optional filtering by data source name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Outputs connection info in {"datasource": ..., "properties": ...}
envelope format, matching the convention used by the MCP web UI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@goldmedal goldmedal force-pushed the feat/cli-docs-command branch from f6cd7d3 to 06daf45 Compare April 2, 2026 02:47
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
wren/src/wren/docs.py (2)

86-104: Consider adding float type mapping.

The helper maps common types to JSON-like labels but doesn't handle float. If any connection info field uses float, it would display as float instead of number. This is a minor consistency improvement.

♻️ Optional fix
     if annotation is int:
         return "integer"
+    if annotation is float:
+        return "number"
     if annotation is str:
         return "string"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@wren/src/wren/docs.py` around lines 86 - 104, The _friendly_type helper
currently maps int->"integer", bool->"boolean", and str/SecretStr->"string" but
lacks a mapping for float; update the _friendly_type function to detect float
and return "number" (add a branch similar to the int/bool cases, e.g., if
annotation is float: return "number") so float-typed annotations render
consistently as "number" (modify the _friendly_type function to include this
check before the generic hasattr/__name__ handling).

259-268: Consider extracting duplicated datasource validation.

The unknown datasource check and error JSON generation is duplicated between generate_json_schema (lines 259-268) and _generate_raw_json_schema (lines 219-228). Consider extracting a helper to reduce duplication.

♻️ Optional refactor
def _resolve_sources(datasource: str | None) -> dict[str, list[type[BaseConnectionInfo]]] | dict[str, Any]:
    """Resolve datasource to sources dict, or return error dict if unknown."""
    if datasource:
        key = datasource.lower()
        if key not in DATASOURCE_MODELS:
            return {"error": f"Unknown data source: {datasource}", "available": sorted(DATASOURCE_MODELS.keys())}
        return {key: DATASOURCE_MODELS[key]}
    return DATASOURCE_MODELS

Then check for "error" key in the result and handle accordingly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@wren/src/wren/docs.py` around lines 259 - 268, Extract the duplicated
datasource validation and error JSON creation used in generate_json_schema and
_generate_raw_json_schema into a small helper (e.g., _resolve_sources) that
accepts datasource: str|None and returns either the resolved mapping of
datasource models or an error dict; update generate_json_schema and
_generate_raw_json_schema to call this helper, detect the error result (e.g.,
presence of "error" key) and return json.dumps(...) only in that branch,
otherwise proceed with the returned models—this removes the duplicated if
datasource / key not in DATASOURCE_MODELS logic and centralizes the available
keys list and error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@wren/src/wren/docs.py`:
- Around line 86-104: The _friendly_type helper currently maps int->"integer",
bool->"boolean", and str/SecretStr->"string" but lacks a mapping for float;
update the _friendly_type function to detect float and return "number" (add a
branch similar to the int/bool cases, e.g., if annotation is float: return
"number") so float-typed annotations render consistently as "number" (modify the
_friendly_type function to include this check before the generic
hasattr/__name__ handling).
- Around line 259-268: Extract the duplicated datasource validation and error
JSON creation used in generate_json_schema and _generate_raw_json_schema into a
small helper (e.g., _resolve_sources) that accepts datasource: str|None and
returns either the resolved mapping of datasource models or an error dict;
update generate_json_schema and _generate_raw_json_schema to call this helper,
detect the error result (e.g., presence of "error" key) and return
json.dumps(...) only in that branch, otherwise proceed with the returned
models—this removes the duplicated if datasource / key not in DATASOURCE_MODELS
logic and centralizes the available keys list and error message.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 353ee574-731f-4c1e-a15d-92b27af5672a

📥 Commits

Reviewing files that changed from the base of the PR and between f565a45 and f6cd7d3.

📒 Files selected for processing (2)
  • wren/src/wren/cli.py
  • wren/src/wren/docs.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wren/src/wren/docs.py`:
- Around line 200-204: The function currently returns an error message string
when an unknown datasource is passed (see the branch that checks key not in
DATASOURCE_MODELS), which causes the CLI to exit 0; change these branches to
raise a non-zero CLI error (e.g., raise click.ClickException(message) or raise
SystemExit(1) with the same message) so the process exits with failure; update
the identical patterns around the other mentioned branches (the blocks at
~221-228 and ~261-268) to raise the exception instead of returning the error
string, referencing DATASOURCE_MODELS and the same error text.
- Around line 273-277: The current loop uses _build_example(model) which omits
optional fields without examples, causing envelope output to drop fields (e.g.,
DatabricksServicePrincipalConnectionInfo.azure_tenant_id). Change the
aggregation so that for each model in the models loop you collect fields from
the model's schema/properties (e.g., model.schema().get("properties", {}) or
model.__fields__) rather than the example object, and build the results entry by
iterating those schema properties and emitting each property's name and
example/default (or null) so all declared fields are present in results; update
the code around the results list and the inner loop that calls _build_example to
use the schema-driven property extraction instead.
- Around line 233-236: When only one datasource was requested, the current loop
builds schemas as {"ds_name": {...}}; change it to emit the schema object itself
when there is exactly one source with one model. In docs.py adjust the logic
around sources, schemas, ds_name, models and model_json_schema so that if
len(sources) == 1 and len(models) == 1 you set the returned value to
models[0].model_json_schema() (not a dict keyed by ds_name); otherwise preserve
the existing dict behavior for multiple sources.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7302be5-3627-42cf-8712-a13d8813ce2c

📥 Commits

Reviewing files that changed from the base of the PR and between f6cd7d3 and 06daf45.

📒 Files selected for processing (2)
  • wren/src/wren/cli.py
  • wren/src/wren/docs.py
✅ Files skipped from review due to trivial changes (1)
  • wren/src/wren/cli.py

- Unknown datasource now raises ValueError → CLI exits with code 1
- Single datasource JSON output returns schema directly without wrapper
- Envelope mode includes all fields (including optional ones)
- Add float → "number" type mapping
- Extract _resolve_sources helper to deduplicate validation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wren/src/wren/docs.py`:
- Around line 173-175: The Markdown table row is built by interpolating raw
variables (name, type_label, required, default, sensitive, alias, example_str)
into a single f-string in docs.py which breaks if any value contains '|' or
newlines; create and use a small helper (e.g., escape_md_cell) to sanitize each
cell before rendering by escaping pipe characters and replacing or normalizing
newlines (e.g., to '<br>' or a space) and then call that helper for each of the
variables passed into the lines.append f-string so the table cells are safe for
Markdown rendering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 855a6c4a-6580-45b7-b35d-be5f7b58aebd

📥 Commits

Reviewing files that changed from the base of the PR and between 06daf45 and 08e9dc2.

📒 Files selected for processing (2)
  • wren/src/wren/cli.py
  • wren/src/wren/docs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren/src/wren/cli.py

Pipe and newline characters in field values could break table
rendering. Add _escape_md_cell helper for safe interpolation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wren/src/wren/docs.py`:
- Around line 196-209: _build_example currently omits optional fields that lack
examples, which drops discriminant/defaulted union tags; update the logic in
_build_example to include optional fields when they have a default value rather
than skipping them: after checking field_info.examples and before continuing on
not field_info.is_required(), test for a present default (e.g.,
field_info.default not being the undefined sentinel or a default factory value)
and set example[key] = that default (or its result), otherwise keep the current
behavior of skipping optional fields without examples; reference
model.model_fields, field_info.examples, field_info.is_required(), and
field_info.default/default_factory in your change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8f823f3-a9a3-4da3-8b32-3f5ab95c716f

📥 Commits

Reviewing files that changed from the base of the PR and between 08e9dc2 and 74edefa.

📒 Files selected for processing (1)
  • wren/src/wren/docs.py

Discriminated union tags like bigquery_type and databricks_type were
dropped from examples because they are optional with non-null defaults.
Now _build_example includes optional fields that have non-null defaults.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@goldmedal goldmedal requested a review from douenergy April 2, 2026 07:18
@douenergy douenergy merged commit 87efbfd into main Apr 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants