API docs: warn when nav is set but header/footer fragments are missing#92
Conversation
Code Review: PR #92 - API docs warning for missing header/footer fragmentsSummaryThis PR adds a helpful generator warning when using the ✅ Strengths
🔍 Code Quality ObservationsStyle Consistency: ✅ The code follows the existing patterns in the file:
Logic Correctness: ✅ The condition properly identifies the problematic configuration:
💡 Suggestions for Consideration1. Template Check - Consider "sidebar" AliasIn if (template is "docs" or "sidebar")
{
GenerateDocsHtml(outputPath, options, types);
return;
}Question: Should the warning also trigger for Suggested change (if applicable): template.Equals("docs", StringComparison.OrdinalIgnoreCase) ||
template.Equals("sidebar", StringComparison.OrdinalIgnoreCase)Or using pattern matching: var templateLower = template.ToLowerInvariant();
if (templateLower is "docs" or "sidebar")2. Warning SpecificityThe current warning requires BOTH HeaderHtmlPath AND FooterHtmlPath to be missing. Consider if a warning should also appear if only ONE is missing, since that would still result in incomplete navigation. However, this depends on whether partial navigation (header-only or footer-only) is a valid use case. 3. Consider Loading NavJsonPath Earlier (Minor)The warning checks if if (\!string.IsNullOrWhiteSpace(options.NavJsonPath) &&
File.Exists(Path.GetFullPath(options.NavJsonPath)) &&
string.IsNullOrWhiteSpace(options.HeaderHtmlPath) &&
string.IsNullOrWhiteSpace(options.FooterHtmlPath) &&
template.Equals("docs", StringComparison.OrdinalIgnoreCase))This would only warn if the NavJsonPath file actually exists, avoiding noise if the path is set but invalid. 🧪 Testing ConsiderationsMissing Test Coverage:
Manual Testing Checklist:
🔒 Security Considerations✅ No security concerns. This change only adds diagnostic output and doesn't modify any execution paths or handle user input in unsafe ways. ⚡ Performance Considerations✅ No performance impact. The validation adds minimal overhead (a few string comparisons) during the initialization phase of document generation. 📋 Overall AssessmentRecommendation: ✅ Approve with minor suggestions This is a clean, well-implemented quality-of-life improvement that will help developers catch configuration issues early. The code is consistent with existing patterns and adds valuable diagnostic information. The only suggestion is to verify whether the "sidebar" template alias should also trigger this warning, based on whether it uses the same header/footer fragment system as "docs". 📝 Minor NitsNone - the code formatting, style, and structure are all consistent with the existing codebase. Great work on improving the developer experience! 🚀 |
There was a problem hiding this comment.
Pull request overview
Adds a generator warning in WebApiDocsGenerator.Generate() to help catch misconfiguration when generating API docs with the docs-style template and a nav config, but without providing header/footer HTML fragments (which results in pages lacking site navigation).
Changes:
- Introduces a new warning when
NavJsonPathis set,Templateisdocs, and bothHeaderHtmlPath/FooterHtmlPathare unset.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!string.IsNullOrWhiteSpace(options.NavJsonPath) && | ||
| string.IsNullOrWhiteSpace(options.HeaderHtmlPath) && | ||
| string.IsNullOrWhiteSpace(options.FooterHtmlPath) && | ||
| template.Equals("docs", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
The warning only triggers when Template == "docs", but GenerateHtml treats both "docs" and "sidebar" as docs-style templates. If users set Template to "sidebar", they can still end up with missing header/footer navigation with NavJsonPath set but won’t get this warning. Consider extending the condition to include the "sidebar" template as well (or reuse the same normalization logic used in GenerateHtml).
| template.Equals("docs", StringComparison.OrdinalIgnoreCase)) | |
| (template.Equals("docs", StringComparison.OrdinalIgnoreCase) || | |
| template.Equals("sidebar", StringComparison.OrdinalIgnoreCase))) |
| if (!string.IsNullOrWhiteSpace(options.NavJsonPath) && | ||
| string.IsNullOrWhiteSpace(options.HeaderHtmlPath) && | ||
| string.IsNullOrWhiteSpace(options.FooterHtmlPath) && | ||
| template.Equals("docs", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
This check only looks at whether HeaderHtmlPath/FooterHtmlPath are non-empty strings. If either path is provided but the file doesn’t exist, LoadOptionalHtml will still return an empty fragment and the docs template will render without navigation, but this warning won’t fire. Consider basing the condition on File.Exists for the provided paths (after GetFullPath) or on whether the loaded header/footer content is actually non-empty.
Pull Request ReviewSummaryThis PR adds a helpful validation warning when using the API docs template with navigation configured but without the required header/footer HTML fragments. This is a good quality-of-life improvement that helps users catch a common configuration mistake early. Code Quality ✅Strengths:
Minor Observations:
Potential Issues 🔍None identified. The code is defensive and follows C# best practices:
Performance Considerations ✅No concerns. The validation logic:
Security Concerns ✅No security issues identified. The code only:
Test Coverage
|
Adds a generator warning when using the docs API template with
av configured but without headerHtml/ooterHtml fragments, since this produces API pages with no site header/footer navigation.