Enhance CLI and logger functionality for improved user experience

- Updated CLI to set log level to "INFO" when verbose mode is enabled.
- Added suggestions for recursive validation when references are found but no endpoints are present.
- Changed default log level in Logger from "INFO" to "WARN" for better log management.
- Improved summary analysis to validate HTTP methods and operation properties more effectively.
This commit is contained in:
Luke Hagar
2025-10-01 23:24:27 +00:00
parent e33cc19f5f
commit b1c9d24e31
3 changed files with 41 additions and 2 deletions

View File

@@ -50,6 +50,12 @@ program
log.setVerbose(options.verbose);
log.setShowProgress(!options.noProgress);
log.setUseColors(!options.noColors);
if (options.verbose) {
log.setLevel("INFO");
}
if (options.verbose) {
log.setLevel("INFO");
}
try {
const validationOptions: ValidationOptions = {
strict: options.strict,
@@ -181,6 +187,19 @@ program
console.log(
` Warnings: ${summary.validationResults.warnings}`
);
// Suggest recursive validation if references are found but endpoints are 0
if (
summary.referenceAnalysis.totalReferences > 0 &&
summary.endpoints === 0
) {
console.log(
"\n💡 Tip: This specification contains references that may not be fully analyzed."
);
console.log(
" Use --recursive flag to validate all referenced schemas and get complete endpoint counts."
);
}
} catch (error) {
// Fallback to basic info if summary generation fails
console.log(`Version: ${validationResult.version}`);
@@ -278,6 +297,9 @@ program
log.setVerbose(options.verbose);
log.setShowProgress(!options.noProgress);
log.setUseColors(!options.noColors);
if (options.verbose) {
log.setLevel("INFO");
}
try {
const parsed = await parse(source);
@@ -413,6 +435,9 @@ program
log.setVerbose(options.verbose);
log.setShowProgress(!options.noProgress);
log.setUseColors(!options.noColors);
if (options.verbose) {
log.setLevel("INFO");
}
try {
const validationOptions: ValidationOptions = {

View File

@@ -54,7 +54,7 @@ export class Logger {
constructor(config: Partial<LoggerConfig> = {}) {
this.config = {
level: "INFO",
level: "WARN",
verbose: false,
showTimestamps: true,
showProgress: true,

View File

@@ -139,10 +139,24 @@ export const analyzeSpecification = (
for (const [path, pathItem] of Object.entries(spec.paths)) {
if (typeof pathItem === "object" && pathItem !== null) {
for (const [method, operation] of Object.entries(pathItem)) {
// Check if this is a valid HTTP method and has operation properties
if (
typeof operation === "object" &&
operation !== null &&
"responses" in operation
[
"get",
"post",
"put",
"delete",
"patch",
"head",
"options",
"trace",
].includes(method.toLowerCase()) &&
("responses" in operation ||
"operationId" in operation ||
"summary" in operation ||
"description" in operation)
) {
endpointCount++;
methods.add(method.toUpperCase());