Skip to content

Conversation

@jdechicchis
Copy link

@jdechicchis jdechicchis commented Jan 8, 2026

I noticed that the keepComments option wasn't being honored when passing a config file like: openapi-format api.yaml -o api.yaml --configFile .openapi-format.json. .openapi-format.json contents:

{
  "keepComments": true
}

Passing the option as a CLI flag worked as expected: openapi-format api.yaml -o api.yaml --keepComments.

Upon some investigation, it appears the source of the bug is with how CLI flags with default values are handled in bin/cli.js. It looks like there was already special handling for flags like lineWidth and sort. This PR adds similar handling for keepComments, sortComponentsProps, and split

Note, this fix could result in the format output differing once folks upgrade their openapi-format version if their current formatting "relied" on these options not being honored when configured via a config file

jdechicchis and others added 2 commits January 8, 2026 10:33
Boolean CLI options with defaults (keepComments, sortComponentsProps, split)
were not being respected when set in a config file. This happened because
Commander.js always sets these options to their default values, and the
subsequent Object.assign would overwrite config file values with CLI defaults.

The fix applies the same pattern already used for lineWidth, sort, and bundle:
explicitly check for config file values before the merge, using nullish
coalescing to preserve CLI-specified values when present.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jdechicchis jdechicchis force-pushed the fix/config-file-boolean-options branch from 67f88a7 to f04cd0e Compare January 8, 2026 16:21
@jdechicchis jdechicchis marked this pull request as ready for review January 8, 2026 16:31
exports[`openapi-format CLI command should respect boolean options from .openapiformatrc 1`] = `
"================================================================================
OpenAPI-Format CLI settings:
- .openapiformatrc: /Users/joseph/oss/openapi-format/.openapiformatrc
Copy link
Owner

Choose a reason for hiding this comment

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

Can you rework this, since it should not snapshot your local user path.

@thim81
Copy link
Owner

thim81 commented Jan 9, 2026

hi @jdechicchis

Nice that you spotted this.
The PR looks in good shape. Thanks for taking the time to create the PR and effort to add tests.

The test runs spotted a small issue with your local user ending up in the snapshot:
https://github.com/thim81/openapi-format/actions/runs/20823748783/job/59920636342?pr=188

If you correct this, the PR will be included in the next release.

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