Skip to content

fix: add support for detecting missing folder in docs/#585

Open
remyleone wants to merge 2 commits intohashicorp:mainfrom
remyleone:fix_missing_folder
Open

fix: add support for detecting missing folder in docs/#585
remyleone wants to merge 2 commits intohashicorp:mainfrom
remyleone:fix_missing_folder

Conversation

@remyleone
Copy link
Copy Markdown
Contributor

@remyleone remyleone commented Apr 15, 2026

Related Issue

Fixes #584

Description

I forgot the documentation for my new list resource and I was surprised to not having an error when I tried to validate the documentation for it. I think it is because when the folder is just not present, no error is raised.

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Copilot AI review requested due to automatic review settings April 15, 2026 16:59
@remyleone remyleone requested a review from a team as a code owner April 15, 2026 16:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve documentation validation by detecting cases where provider schemas define documentable entities (e.g., list resources/state stores/actions) but the corresponding documentation subfolders under docs/ (and website/docs/) are missing—so missing docs are surfaced as validation errors instead of being skipped.

Changes:

  • Populate mismatch-check entry lists with empty slices when schemas exist but the docs subdirectory is missing (to force the mismatch check to run).
  • Update ResourceFileMismatchCheck to treat “no files” as “missing documentation” when schemas exist (instead of skipping).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/provider/validate.go Pass empty directory-entry slices for select doc categories when schema exists but docs folder is missing.
internal/check/file_mismatch.go Change resource mismatch behavior to error when schemas exist but no files are present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/provider/validate.go Outdated
Comment on lines +320 to +322
} else if len(v.providerSchema.ActionSchemas) > 0 {
// If actions exist in schema but directory doesn't, create empty slice to trigger validation
mismatchOpt.ActionEntries = []os.DirEntry{}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The new empty slice assignment is intended to "trigger validation", but FileMismatchCheck calls ActionFileMismatchCheck for actions and that function currently returns early when len(files) == 0. As a result, missing docs/actions (or an empty actions folder) will still be silently skipped even when ActionSchemas exist. Consider updating ActionFileMismatchCheck to treat an empty/non-nil files list as missing documentation (similar to ResourceFileMismatchCheck), or adjust the mismatch check logic so actions are validated when schemas exist but the directory is absent.

Copilot uses AI. Check for mistakes.
Comment thread internal/provider/validate.go Outdated
Comment on lines +428 to +430
} else if len(v.providerSchema.ActionSchemas) > 0 {
// If actions exist in schema but directory doesn't, create empty slice to trigger validation
mismatchOpt.ActionEntries = []os.DirEntry{}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

Same issue as in validateStaticDocs: setting ActionEntries to an empty slice will not currently trigger a missing-docs error because ActionFileMismatchCheck short-circuits when len(files) == 0. Missing website/docs/actions (or an empty folder) will therefore still be skipped even if ActionSchemas exist.

Suggested change
} else if len(v.providerSchema.ActionSchemas) > 0 {
// If actions exist in schema but directory doesn't, create empty slice to trigger validation
mismatchOpt.ActionEntries = []os.DirEntry{}
if len(v.providerSchema.ActionSchemas) > 0 && len(actionFiles) == 0 {
result = errors.Join(result, fmt.Errorf("actions documentation directory %q is missing or empty", filepath.Join(dir, "actions")))
}
} else if len(v.providerSchema.ActionSchemas) > 0 {
result = errors.Join(result, fmt.Errorf("actions documentation directory %q is missing or empty", filepath.Join(dir, "actions")))

Copilot uses AI. Check for mistakes.
Comment on lines +115 to 124
if len(files) == 0 {
// No files found, report all schemas as missing documentation
for _, resourceName := range resourceNames(schemas) {
if check.IgnoreFileMissing(resourceName) {
continue
}
log.Printf("[DEBUG] Missing file for %s %s", resourceType, resourceName)
return fmt.Errorf("missing documentation file for %s: %s", resourceType, resourceName)
}
return nil
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

When len(files) == 0, this loop returns on the first non-ignored schema, so it does not actually "report all schemas" and also behaves inconsistently with the rest of the function (which aggregates multiple missing/extra items via errors.Join). Consider collecting all non-ignored schema names and returning a joined error for each missing doc (or reusing the existing missingFiles aggregation path).

Copilot uses AI. Check for mistakes.
Comment on lines +117 to 124
for _, resourceName := range resourceNames(schemas) {
if check.IgnoreFileMissing(resourceName) {
continue
}
log.Printf("[DEBUG] Missing file for %s %s", resourceType, resourceName)
return fmt.Errorf("missing documentation file for %s: %s", resourceType, resourceName)
}
return nil
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The new behavior for an empty (but non-nil) files list is not covered by tests. Given this is intended to detect missing documentation directories, please add unit tests that pass an empty slice for ResourceEntries/ListResourceEntries/StateStoreEntries while schemas are present, and assert that the error includes all missing schema names (including ignored vs non-ignored behavior).

Suggested change
for _, resourceName := range resourceNames(schemas) {
if check.IgnoreFileMissing(resourceName) {
continue
}
log.Printf("[DEBUG] Missing file for %s %s", resourceType, resourceName)
return fmt.Errorf("missing documentation file for %s: %s", resourceType, resourceName)
}
return nil
var result error
for _, resourceName := range resourceNames(schemas) {
if check.IgnoreFileMissing(resourceName) {
continue
}
log.Printf("[DEBUG] Missing file for %s %s", resourceType, resourceName)
err := fmt.Errorf("missing documentation file for %s: %s", resourceType, resourceName)
result = errors.Join(result, err)
}
return result

Copilot uses AI. Check for mistakes.
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.

Validate silently pass in case there is no directory for list resources

2 participants