Skip to content

schema gen support starlight migration#6119

Open
glmnet wants to merge 1 commit intoesphome:currentfrom
glmnet:schema-fix-sl-migration
Open

schema gen support starlight migration#6119
glmnet wants to merge 1 commit intoesphome:currentfrom
glmnet:schema-fix-sl-migration

Conversation

@glmnet
Copy link
Member

@glmnet glmnet commented Feb 19, 2026

Description

Quick fix to get schema filled with docs from the new path and mdx extension.
Parser might need updates but with this will fix the schema gen action on https://github.com/esphome/esphome-schema/actions and get most of docs back there.

Checklist

  • I am merging into next because this is new documentation that has a matching pull-request in esphome as linked above.
    or

  • I am merging into current because this is a fix, change and/or adjustment in the current documentation and is not for a new component or feature.

  • Link added in /src/content/docs/components/index.mdx when creating new documents for new components or cookbook.

@esphome esphome bot added the current label Feb 19, 2026
@netlify
Copy link

netlify bot commented Feb 19, 2026

Deploy Preview for esphome ready!

Name Link
🔨 Latest commit 7d32766
🔍 Latest deploy log https://app.netlify.com/projects/esphome/deploys/69967405d2c1de0008dace59
😎 Deploy Preview https://deploy-preview-6119--esphome.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

Walkthrough

A single file script/schema_doc.py is updated to centralize documentation path handling. A new DOCS_ROOT constant replaces hardcoded path references, file extensions are migrated from .md to .mdx, and doc paths are updated to use the new base path. An else-branch for unknown component types is added to the schema processing flow.

Changes

Cohort / File(s) Summary
Documentation Path Refactoring
script/schema_doc.py
Introduced DOCS_ROOT constant (src/content/docs), replaced all hardcoded content paths with DOCS_ROOT references, updated file extensions from .md to .mdx throughout, and added else-branch for unknown component type handling in schema processing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Add-schema_docs-for-md #5281 — Updates the same schema_doc.py documentation generation pipeline with DOCS_ROOT constant and .mdx path modifications.

Suggested labels

next

Suggested reviewers

  • jesserockz
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly relates to the main change—updating schema documentation generation to support the Starlight migration with new paths and mdx extensions.
Description check ✅ Passed The description clearly explains the purpose of the changes: fixing schema generation after a Starlight migration by updating paths and file extensions.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

Copy link
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: 2

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

Inline comments:
In `@script/schema_doc.py`:
- Around line 29-30: SeeAlso.md() and convert_links_and_shortcodes are building
URLs by slicing path.parts[1:-1], which breaks when DOCS_ROOT has extra path
segments; change both to compute the path relative to DOCS_ROOT (use
Path.relative_to(DOCS_ROOT) or Path.resolve().relative_to(DOCS_ROOT.resolve()))
and build the URL from that relative path's parts (remove the file suffix and
join remaining parts with '/'), replacing the hardcoded parts[1:-1] logic so
generated URLs are relative to DOCS_ROOT regardless of its depth.
- Around line 407-416: The fallback lookup currently checks for "_index.mdx" and
the guards compare file_name == "_index", but the repo uses "index.mdx" so these
branches never match; update the fallback in the ref resolution (variable
ref_md_default) to look for ref / "index.mdx" (and the DOCS_ROOT components
fallback to (ref + ".mdx") remains), and change the guards that compare
file_name == "_index" to compare file_name == "index" (search for uses of
md_file.stem and the variables file_name around the checks at the two locations)
so directory index pages are detected correctly.

Comment on lines +29 to +30
DOCS_ROOT = Path(".") / "src" / "content" / "docs"

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

URL generation in SeeAlso.md() and convert_links_and_shortcodes is broken by the new path depth.

DOCS_ROOT now resolves to PosixPath("src/content/docs") (3 parts), so doc files have paths like src/content/docs/components/sensor.mdx with parts ('src', 'content', 'docs', 'components', 'sensor.mdx').

Both SeeAlso.md() (line 75) and convert_links_and_shortcodes (line 452) use the hardcoded parts[1:-1] slice, which was designed for a 1-level prefix (content/):

Structure parts[1:-1] Generated URL
Old: content/components/sensor.md ('components',) /components/sensor
New: src/content/docs/components/sensor.mdx ('content', 'docs', 'components') /content/docs/components/sensor

This will cause all "See also" links and relative docref shortcode URLs written into the schema JSON to be incorrect. Fix by making the URL slice relative to DOCS_ROOT:

🐛 Proposed fix — derive URL relative to `DOCS_ROOT`

Apply to SeeAlso.md() (line 75):

 def md(self):
-    url_path = "/" + "/".join(list(self.file.parts[1:-1]))
-    if self.file.stem != "_index":
-        url_path += f"/{self.file.stem}"
+    relative = self.file.relative_to(DOCS_ROOT)
+    url_path = "/" + "/".join(relative.parts[:-1])
+    if self.file.stem not in ("_index", "index"):
+        url_path += f"/{self.file.stem}"

Apply to convert_links_and_shortcodes (line 452):

-    url = args.deploy_url + "/" + "/".join(md_file.parts[1:-1]) + "/" + ref
+    url = args.deploy_url + "/" + "/".join(md_file.relative_to(DOCS_ROOT).parts[:-1]) + "/" + ref
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@script/schema_doc.py` around lines 29 - 30, SeeAlso.md() and
convert_links_and_shortcodes are building URLs by slicing path.parts[1:-1],
which breaks when DOCS_ROOT has extra path segments; change both to compute the
path relative to DOCS_ROOT (use Path.relative_to(DOCS_ROOT) or
Path.resolve().relative_to(DOCS_ROOT.resolve())) and build the URL from that
relative path's parts (remove the file suffix and join remaining parts with
'/'), replacing the hardcoded parts[1:-1] logic so generated URLs are relative
to DOCS_ROOT regardless of its depth.

Comment on lines +407 to 416
ref_md_path = md_parent / (ref + ".mdx")
if ref_md_path.exists():
return ref_md_path
ref_md_default = md_parent / ref / "_index.md"
ref_md_default = md_parent / ref / "_index.mdx"
if ref_md_default.exists():
return ref_md_default
ref_md_default = Path(".") / "content" / "components" / (ref + ".md")
ref_md_default = DOCS_ROOT / "components" / (ref + ".mdx")
if ref_md_default.exists():
return ref_md_default
return md_file # go nowhere
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check the actual MDX files in the docs structure
find src/content/docs -type f -name "*index.mdx" 2>/dev/null | head -30

Repository: esphome/esphome-docs

Length of output: 1439


🏁 Script executed:

# Check for _index.mdx files specifically
find src/content/docs -type f -name "_index.mdx" 2>/dev/null | head -30

Repository: esphome/esphome-docs

Length of output: 46


🏁 Script executed:

# Get context around lines 407-416, 765, and 787 in script/schema_doc.py
sed -n '400,420p' script/schema_doc.py

Repository: esphome/esphome-docs

Length of output: 662


🏁 Script executed:

# Check line 765 context
sed -n '760,770p' script/schema_doc.py

Repository: esphome/esphome-docs

Length of output: 449


🏁 Script executed:

# Check line 787 context
sed -n '780,795p' script/schema_doc.py

Repository: esphome/esphome-docs

Length of output: 827


🏁 Script executed:

# Search for where file_name is assigned before line 787
sed -n '700,790p' script/schema_doc.py | grep -n "file_name"

Repository: esphome/esphome-docs

Length of output: 218


🏁 Script executed:

# Get broader context around the file processing loop
sed -n '680,810p' script/schema_doc.py

Repository: esphome/esphome-docs

Length of output: 4850


Update _index.mdx references to index.mdx — Hugo migration incomplete.

The codebase uses index.mdx for directory index files (confirmed across src/content/docs/), but the fallback lookup at line 410 still searches for _index.mdx, which no longer exists. Similarly, the guards at lines 787 and 797 check file_name == "_index", but file_name = md_file.stem will be index for actual files, so these conditions never match.

Update all three locations to use the index convention:

Proposed fixes

Line 410:

-    ref_md_default = md_parent / ref / "_index.mdx"
+    ref_md_default = md_parent / ref / "index.mdx"

Line 787:

-        if file_name == "_index" and content_folder == "components":
+        if file_name == "index" and content_folder == "components":

Line 797:

-            if file_name == "_index":
+            if file_name == "index":
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ref_md_path = md_parent / (ref + ".mdx")
if ref_md_path.exists():
return ref_md_path
ref_md_default = md_parent / ref / "_index.md"
ref_md_default = md_parent / ref / "_index.mdx"
if ref_md_default.exists():
return ref_md_default
ref_md_default = Path(".") / "content" / "components" / (ref + ".md")
ref_md_default = DOCS_ROOT / "components" / (ref + ".mdx")
if ref_md_default.exists():
return ref_md_default
return md_file # go nowhere
ref_md_path = md_parent / (ref + ".mdx")
if ref_md_path.exists():
return ref_md_path
ref_md_default = md_parent / ref / "index.mdx"
if ref_md_default.exists():
return ref_md_default
ref_md_default = DOCS_ROOT / "components" / (ref + ".mdx")
if ref_md_default.exists():
return ref_md_default
return md_file # go nowhere
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@script/schema_doc.py` around lines 407 - 416, The fallback lookup currently
checks for "_index.mdx" and the guards compare file_name == "_index", but the
repo uses "index.mdx" so these branches never match; update the fallback in the
ref resolution (variable ref_md_default) to look for ref / "index.mdx" (and the
DOCS_ROOT components fallback to (ref + ".mdx") remains), and change the guards
that compare file_name == "_index" to compare file_name == "index" (search for
uses of md_file.stem and the variables file_name around the checks at the two
locations) so directory index pages are detected correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments