Skip to content

feat: JSONC support (library, CLI, validator, REST API) + v0.16.3 - #147

Open
Artifizer wants to merge 3 commits into
mainfrom
jsonc
Open

Artifizer wants to merge 3 commits into
mainfrom
jsonc

Conversation

@Artifizer

@Artifizer Artifizer commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds JSONC (JSON with // / /* */ comments and trailing commas) support across the crates. Before this change, .jsonc files were discovered, but any comment made them fail to parse and they were silently skipped. That includes the // Invalid: examples the gts-spec example generator writes.

  • gts::jsonc (new public module): strip blanks comments, trailing commas and a leading UTF-8 BOM in place. Byte offsets and line breaks are kept, so serde_json errors point at the original line and column. No new dependencies.
  • Library / CLI / validator: *.jsonc is parsed as JSONC by GtsFileReader, gts validate-json (which now also discovers .jsonc) and gts-validator. *.json stays strict JSON.
  • Config: --config <file>.jsonc and a default gts.config.jsonc are supported; gts.config.json wins if both exist. Unreadable or malformed config files now produce a warning instead of being ignored silently.
  • REST API: Content-Type: application/jsonc bodies are accepted on every endpoint. A middleware strips them and forwards application/json, so handlers, the effective DefaultBodyLimit and the 400/413/422 rejections are the same as for JSON. application/json stays strict.
  • fix(gts-cli): CLI logs now go to stderr, so warnings no longer corrupt the JSON results on stdout (gts ... | jq). Server -v logs move to stderr too; make gts-server / gts-spec-tests already capture both streams.
  • chore: bump all GTS crates to v0.16.3. gts-validator depends on the new gts::jsonc module.

Behavior changes to be aware of

  • gts --path <dir> now loads entities from .jsonc files with comments. For example, pointing it at gts-test-examples/ registers the invalid/*.jsonc examples, which were previously skipped.
  • gts-validator now scans .jsonc files, which may surface new findings in CI.
  • gts-python, gts-go and gts-dotnet still parse .jsonc as strict JSON; they will be aligned separately.

Test plan

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -D warnings
  • cargo test --workspace. New tests cover the stripper (comments, trailing commas, BOM, strings containing comment markers, malformed input, error positions), .jsonc loading in the file reader / validate-json / gts-validator, config precedence and fallback, and the REST server (JSONC bodies, media-type parameters and case, strict application/json, 400/413/422 parity, outer DefaultBodyLimit, non-UTF-8 bodies)
  • Manual: 300 real gts-test-examples/invalid/types/*.jsonc files now parse in gts list, gts validate-json and gts-validator (0 parse errors); live server returns 200 for a JSONC file sent as application/jsonc and 400 as application/json
  • make gts-spec-tests (needs Docker; not run locally)
  • make dylint (not run locally)

Summary by CodeRabbit

  • New Features
    • Added support for JSONC files, including comments and trailing commas, in file reading, validation, and identifier scanning.
    • The HTTP API now accepts JSONC request bodies when sent as application/jsonc.
    • Configuration can now be loaded from gts.config.jsonc, alongside gts.config.json.
  • Documentation
    • Updated usage guidance to describe JSONC support across configuration, validation, and API requests.

JSONC adds `//` and `/* */` comments and trailing commas to JSON. `.jsonc`
files with comments, such as the `// Invalid:` examples written by the
gts-spec example generator, were silently skipped because they were parsed
as strict JSON.

- Add `gts::jsonc`: `strip` blanks comments, trailing commas and a leading
  UTF-8 BOM in place, keeping byte offsets and line breaks so `serde_json`
  errors point at the original line and column. No new dependencies.
- Parse `*.jsonc` as JSONC in `GtsFileReader`, `gts validate-json` (which now
  also discovers `.jsonc` files) and `gts-validator`; `*.json` stays strict.
- Accept `--config <file>.jsonc` and a default `gts.config.jsonc`;
  `gts.config.json` wins if both exist. Unreadable or malformed config files
  are now reported with a warning instead of being ignored silently.
- REST server: accept `Content-Type: application/jsonc` bodies on every
  endpoint. A middleware strips them and forwards `application/json`, so the
  handlers, the effective `DefaultBodyLimit` and the 400/413/422 rejections
  are the same as for JSON. `application/json` stays strict.

Signed-off-by: Artifizer <artifizer@gmail.com>
The tracing subscriber wrote to stdout, so any warning was mixed into the
JSON results the CLI prints there and broke piping into tools such as `jq`.
Server `-v`/`-vv` logs move to stderr as well; the request/response logging
middleware already used stderr.

Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 873c39bb-2c46-4fe0-ba35-5bcd4de8d04b
Commits

Reviewing files that changed from the base of the PR and between 45d7ac9 and 10dd794.

Files ignored due to path filters: 2
  • Cargo.lock is excluded by !**/*.lock
  • gts-dylint/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 24
  • Cargo.toml
  • README.md
  • gts-cli/Cargo.toml
  • gts-cli/src/cli.rs
  • gts-cli/src/json_validation.rs
  • gts-cli/src/server.rs
  • gts-cli/tests/server_tests.rs
  • gts-dylint/Cargo.toml
  • gts-id/Cargo.toml
  • gts-macros-cli/Cargo.toml
  • gts-macros/Cargo.toml
  • gts-validator/Cargo.toml
  • gts-validator/README.md
  • gts-validator/src/format/mod.rs
  • gts-validator/src/lib.rs
  • gts-validator/src/main.rs
  • gts-validator/src/strategy/fs.rs
  • gts-validator/src/strategy/mod.rs
  • gts-validator/tests/validate_fs_tests.rs
  • gts/Cargo.toml
  • gts/src/files_reader.rs
  • gts/src/jsonc.rs
  • gts/src/lib.rs
  • gts/src/ops.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change adds JSONC parsing and support for configuration files, filesystem validation, and HTTP request bodies. It also updates crate versions to 0.16.3 and directs CLI tracing output to stderr.

Changes: JSONC support

Layer / File(s) Summary
JSONC parsing and file reading
gts/src/jsonc.rs, gts/src/lib.rs, gts/src/files_reader.rs
A public parser strips comments, trailing commas, and a leading BOM while preserving offsets and line breaks. File reading uses the path extension to choose JSONC or strict JSON parsing.
Configuration file loading
gts/src/ops.rs, README.md
Configuration loading checks an explicit path first, then gts.config.json and gts.config.jsonc. Tests cover precedence and fallback. The README documents JSONC configuration files.
CLI JSON and JSONC validation
gts-cli/src/json_validation.rs, gts-cli/src/cli.rs, README.md
The CLI discovers and parses JSON and JSONC files. Tests cover single-file and directory validation. The README adds JSONC input references.
Filesystem validator JSONC scanning
gts-validator/src/strategy/*, gts-validator/src/format/mod.rs, gts-validator/src/lib.rs, gts-validator/src/main.rs, gts-validator/tests/validate_fs_tests.rs, gts-validator/README.md
The validator discovers JSONC files and strips JSONC before scanning. Tests cover valid and invalid identifiers and confirm that JSONC syntax under a .json extension fails.
JSONC HTTP request bodies
gts-cli/src/server.rs, gts-cli/tests/server_tests.rs, README.md
Router middleware recognizes application/jsonc, strips JSONC text, and forwards the body as application/json. Tests cover endpoint behavior, media types, malformed input, encoding, and body limits.

Crate version updates

Layer / File(s) Summary
Workspace and package versions
Cargo.toml, gts*/Cargo.toml
Workspace dependency constraints and package versions change from 0.16.2 to 0.16.3.

CLI tracing output

Layer / File(s) Summary
Tracing output destination
gts-cli/src/cli.rs
The CLI tracing subscriber writes output to stderr.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant accept_jsonc_body
  participant AxumEndpoint
  Client->>accept_jsonc_body: POST with application/jsonc body
  accept_jsonc_body->>AxumEndpoint: Forward stripped body as application/json
  AxumEndpoint->>Client: Return endpoint response
Loading

Possibly related PRs

Suggested reviewers: aviator5, devjow

Merge Risk: Minimal · up to 10dd7

No identified issue blocks merging; complete the normal checks before release.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 60 functions across 14 files. (10 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change, JSONC support across the library, CLI, validator, and REST API, and the version bump to 0.16.3.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 60 functions across 14 files. (10 skipped: 10 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@code-ranker-app

Copy link
Copy Markdown
Contributor

code-ranker View diff report ↗

rust
Metric Baseline Current Δ
sum always
Files 56 57 +1
Edges 238 244 +6
Complexity
cognitive — Cognitive complexity 52.7 52.3 $\color{#2a7a30}{-0.413}$
cyclomatic — Cyclomatic complexity 76.7 76.2 $\color{#2a7a30}{-0.494}$
Coupling
fan_in — Incoming dependencies 3.4 3.4 +0.036
fan_out — Outgoing dependencies 3.7 3.8 +0.122
hk — God-object risk 383.3K 389.1K $\color{#c0392b}{+5826}$
Halstead
bugs — Estimated bugs 2.1 2.1 $\color{#2a7a30}{-0.017}$
effort — Implementation effort 772.2K 762.6K $\color{#2a7a30}{-9670}$
length — Total tokens 1352 1344 $\color{#2a7a30}{-7.9}$
time — Coding time (s) 42.9K 42.4K $\color{#2a7a30}{-537}$
vocabulary — Distinct symbols 149 149 $\color{#c0392b}{+0.061}$
volume — Code volume 10.9K 10.8K $\color{#2a7a30}{-63.3}$
Lines of Code
blank — Blank lines 34.1 33.8 -0.336
cloc — Comment lines 85.6 84.9 -0.708
sloc — Source lines 295 293 -2.5
tloc — Test lines 332 322 -10.1
Maintainability
mi — Maintainability index 43.4 43.3 $\color{#c0392b}{-0.139}$
mi_sei — Maintainability (SEI) 50.3 49.1 $\color{#c0392b}{-1.2}$

baseline main @45d7ac9 2026-10-23 11:32 UTC · updated 2026-10-25 17:20 UTC

@Artifizer
Artifizer requested a review from aviator5 October 25, 2026 17:55

This branch has not been deployed

No deployments
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.

1 participant