Skip to content

fix(settings): keep doc comments on every list item in generated YAML - #283

Open
RaphaelFakhri wants to merge 1 commit into
cloudflare:mainfrom
RaphaelFakhri:fix/settings-list-item-docs
Open

RaphaelFakhri wants to merge 1 commit into
cloudflare:mainfrom
RaphaelFakhri:fix/settings-list-item-docs

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

to_yaml_string reset its list item counter on every key line that is not a list item. When a list item has more than one key, the counter is back at 0 before the next item starts, so every item after the first is looked up as item 0. Docs that exist only for a later item are then dropped from the generated YAML, for example the fields of an Option that is None in the first item and Some in a later one. This affects Cli's --generate output and to_yaml_file with both the serde_yaml and serde-saphyr backends.

This change tracks the next item index for each enclosing list by its indentation. A list item line continues the list at its indentation and ends any list nested in the previous item. A key line at or left of a list's dash ends that list.

Before

  - name: bar
    # Optional field
    optional:
      a: 1
      b: 2
      c: 3

After

  - name: bar
    # Optional field
    optional:
      # A field, which is named the same as another field.
      a: 1
      # multi-line
      # doc comment
      b: 2
      c: 3

Testing

  • Added vec_items_with_different_fields to foundations/tests/settings.rs, with expected output for both YAML backends. It fails without the fix and passes with it.
  • cargo test -p foundations --no-default-features --features settings --test settings: 13 passed, with and without --features serde-saphyr.
  • cargo fmt --all -- --check and the clippy command from AGENTS.md (on --lib --test settings) are clean.

Fixes #282

to_yaml_string reset its list item counter on every non-list key, so
each list item after the first was looked up as item 0. Docs that only
exist for a later item, such as the fields of an Option that is None in
the first item and Some in a later one, were dropped.

Track the next item index per list indentation instead.
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.

Generated settings YAML drops doc comments for later list items

1 participant