Skip to content

feat: zss, zss to json schema and json schema for zss - #226

Merged
Oudwins merged 14 commits into
masterfrom
feat/zss
Jul 5, 2026
Merged

feat: zss, zss to json schema and json schema for zss#226
Oudwins merged 14 commits into
masterfrom
feat/zss

Conversation

@Oudwins

@Oudwins Oudwins commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a CLI command to generate versioned ZSS JSON Schemas, with inline output and support for writing to a custom destination.
    • Introduced JSON Schema conversion for ZSS documents using Draft 2020-12, including test/constraint translation and field metadata support.
    • Added a make schema-gen shortcut for schema generation.
  • Bug Fixes

    • Improved schema output determinism (stable key ordering) and ensured consistent trailing newlines.
    • Improved handling of optional/nullable pointers and required fields.
  • Tests

    • Added extensive test coverage for schema generation and ZSS→JSON Schema conversion.
  • Chores

    • Updated Go toolchain version.

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a7daaf0e-26f6-4f77-9812-81b3e7bfe16f

📥 Commits

Reviewing files that changed from the base of the PR and between 59838cc and 931bea4.

📒 Files selected for processing (5)
  • docs/static/zss/0.0.1/schema.json
  • pkgs/zss/jsonschema/draft2020_12/jsonschema.go
  • pkgs/zss/jsonschema/jsonschema_test.go
  • pkgs/zss/regexconv/regexconv.go
  • pkgs/zss/regexconv/regexconv_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/static/zss/0.0.1/schema.json
  • pkgs/zss/jsonschema/draft2020_12/jsonschema.go

Walkthrough

This PR adds generic, reflection-aware ZSS serialization, a draft 2020-12 ZSS-to-JSON-Schema converter, a schema-generation CLI, and updates tests to the new generic API and metadata model.

Changes

ZSS JSON Schema Generation and Type-Driven Serialization

Layer / File(s) Summary
Generic serialization and field metadata
toZSS.go, recursive.go, pkgs/zss/core/zss_structures.go, pkgs/zss/schema/zss_document_schema.go, pkgs/zss/toZSS_type_metadata_test.go
EXPERIMENTAL_TO_ZSS becomes generic and type-aware, recursive refs use the current reflected type, and ZSS schema/core types gain FieldMeta support plus relaxed go-type validation.
JSON Schema conversion API and draft 2020-12
pkgs/zss/jsonschema/*, pkgs/zss/regexconv/*
Adds the shared schema API, draft-selected ZSS→JSON Schema conversion, processor/test conversion, regex group normalization, and tests for conversion, nullability, and error paths.
Schema generator CLI and emitted schema
cmd/zssschema-gen/*, Makefile, go.mod, docs/static/zss/0.0.1/schema.json
Adds the schema generator CLI, deterministic JSON output, a make schema-gen target, updated module requirements, and the generated schema file.
Generic test migration
pkgs/zss/toZSS_*_test.go
Updates existing tests to pass explicit type parameters, revises GoTypes assertions for meta/no-meta cases, and strips GoTypes where JSON comparisons need stable output.

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

Possibly related PRs

  • Oudwins/zog#223: This PR extends the same ZSS core schema structures and type-driven serialization path that are modified in the referenced work.
  • Oudwins/zog#213: Both changes touch the ZSSSchema shape in pkgs/zss/core/zss_structures.go.

Poem

A rabbit typed the schemas bright,
With tags and refs and JSON light.
It hopped through drafts from dawn to noon,
And sang, “My types all match the tune!” 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 is broadly aligned with the PR’s core change: adding ZSS↔JSON Schema support, though it is a bit awkward and broad.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/zss

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 16, 2026

Copy link
Copy Markdown

Deploying zog with  Cloudflare Pages  Cloudflare Pages

Latest commit: 931bea4
Status: ✅  Deploy successful!
Preview URL: https://acb3ab35.zog-3a0.pages.dev
Branch Preview URL: https://feat-zss.zog-3a0.pages.dev

View logs

@Oudwins
Oudwins force-pushed the feat/zss branch 2 times, most recently from 8316554 to 04e0062 Compare May 16, 2026 18:52
@Oudwins
Oudwins marked this pull request as ready for review June 8, 2026 05:19
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds JSON Schema support for ZSS documents. The main changes are:

  • New ZSS-to-JSON-Schema converter for draft 2020-12.
  • New schema generation command and Makefile target.
  • Generated schema artifact under docs/static/zss.
  • Field metadata support for ZSS struct fields.
  • Updated ZSS serialization tests for the new schema shape.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
toZSS.go Updates ZSS serialization to carry reflected type metadata through structs, pointers, slices, maps, preprocessors, boxed schemas, and definitions.
pkgs/zss/jsonschema/draft2020_12/jsonschema.go Adds draft 2020-12 JSON Schema conversion for ZSS documents, including struct fields, nullability, refs, containers, and validation processors.
cmd/zssschema-gen/main.go Adds a command for generating versioned ZSS JSON Schema output to stdout or a file.
docs/static/zss/0.0.1/schema.json Adds the generated JSON Schema document for ZSS version 0.0.1.

Reviews (4): Last reviewed commit: "chore: fix zog schema regex" | Re-trigger Greptile

Comment thread toZSS.go
Comment thread pkgs/zss/jsonschema/draft2020_12/jsonschema.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
cmd/zssschema-gen/main_test.go (1)

15-93: ⚡ Quick win

Add coverage for the -base-url contract.

Line 44 introduces a user-facing flag, but current tests never assert $id generation for non-default base URLs.

Suggested test addition
+func TestRunUsesCustomBaseURL(t *testing.T) {
+	var stdout, stderr bytes.Buffer
+
+	err := run([]string{
+		"-version", "0.0.1",
+		"-inline",
+		"-base-url", "https://example.dev/custom/zss/",
+	}, &stdout, &stderr)
+
+	require.NoError(t, err)
+	assert.Empty(t, stderr.String())
+
+	var schema map[string]any
+	require.NoError(t, json.Unmarshal(stdout.Bytes(), &schema))
+	assert.Equal(t, "https://example.dev/custom/zss/0.0.1/schema.json", schema["$id"])
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/zssschema-gen/main_test.go` around lines 15 - 93, Add a test that
exercises the -base-url flag and asserts it affects the generated $id: call
run(...) with "-version", a valid version, "-inline" (or "-out" for file path)
and "-base-url", capture stdout/stderr and unmarshal JSON, then assert
schema["$id"] equals the provided base URL plus "/zss/<version>/schema.json;
e.g. add TestRunUsesBaseURL (or extend TestRunWritesSchemaToStdoutWithInline) to
call run with "-base-url", verify stderr is empty, and assert the exact $id
value and that stdout begins with the expected JSON prefix. Ensure you reference
the existing run(...) helper and use the same json.Unmarshal checks as other
tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkgs/zss/jsonschema/draft2020_12/jsonschema.go`:
- Around line 99-113: The UnknownKindConverter may legally return (nil, nil)
which leads to panics when later code writes to out or when c.applyProcessors is
called; update the branch that calls c.opts.UnknownKindConverter in method where
out is assigned so that after calling c.opts.UnknownKindConverter(schema) you
normalize a nil out to an empty Schema (e.g., if out == nil { out = Schema{} })
before any use or before calling c.applyProcessors(out, schema) and before the
function returns; reference the UnknownKindConverter call site, the local
variable out, the applyProcessors method, and the Schema type when making this
change.
- Around line 134-151: The required slice is populated by iterating the map
schema.Fields which yields nondeterministic order; before assigning it into
out["required"] (after building properties in the loop that calls
c.convertSchema and uses propertyName(schema.FieldMeta[name], name)), sort the
required slice (e.g., using sort.Strings) so the emitted JSON Schema has a
deterministic order; ensure you import the sort package if needed and perform
the sort right before the line that sets out["required"] = required.

In `@pkgs/zss/toZSS_processors_test.go`:
- Line 65: The tests call zog.EXPERIMENTAL_TO_ZSS with incorrect generic type
parameters (e.g., int for schemas built with zog.String()), so update each test
invocation of EXPERIMENTAL_TO_ZSS to use the schema root's actual Go type: for
schemas created via zog.String() use string, for zog.Int() use int, for
zog.Bool() use bool, etc.; locate usages of EXPERIMENTAL_TO_ZSS in
toZSS_processors_test.go (lines shown in the review) and replace the mismatched
type arguments so the generic T matches the schema root type for each test case.

In `@schemas/zss/0.0.1/schema.json`:
- Line 34: The schema's "pattern" values in schemas/zss/0.0.1/schema.json use
Python-style named groups `(?P<name>...)` which are not portable for
draft-2020-12; update the generator that emits these regexes so it replaces
`(?P<...>...)` with standard groups (either non-capturing `(?:...)` or plain
`(...)` as appropriate) for all occurrences (the pattern properties currently
containing `(?P<id>...)` and `(?P<version>...)`), then regenerate the schema so
the file contains only JSON-Schema-compatible regex syntax.

In `@toZSS.go`:
- Around line 107-119: In fieldTypeForShapeKey, guard against empty keys and
avoid the fixed 32-byte buffer that can be out-of-bounds: if key == "" return
(reflect.StructField{}, false); to uppercase the first byte when it's lowercase,
allocate a byte slice of length len(key) (or convert to []byte(key)), modify
index 0, and build the string from that slice (instead of using a fixed [32]byte
and slicing it). Keep the existing indirectType and t.Kind() checks and then
call t.FieldByName(fieldName).

---

Nitpick comments:
In `@cmd/zssschema-gen/main_test.go`:
- Around line 15-93: Add a test that exercises the -base-url flag and asserts it
affects the generated $id: call run(...) with "-version", a valid version,
"-inline" (or "-out" for file path) and "-base-url", capture stdout/stderr and
unmarshal JSON, then assert schema["$id"] equals the provided base URL plus
"/zss/<version>/schema.json; e.g. add TestRunUsesBaseURL (or extend
TestRunWritesSchemaToStdoutWithInline) to call run with "-base-url", verify
stderr is empty, and assert the exact $id value and that stdout begins with the
expected JSON prefix. Ensure you reference the existing run(...) helper and use
the same json.Unmarshal checks as other tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9b4c6cf6-bb4f-416b-8a5b-421a0fc94969

📥 Commits

Reviewing files that changed from the base of the PR and between c32cea0 and 0657aca.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (20)
  • cmd/zssschema-gen/main.go
  • cmd/zssschema-gen/main_test.go
  • go.mod
  • pkgs/zss/core/zss_structures.go
  • pkgs/zss/jsonschema/draft2020_12/jsonschema.go
  • pkgs/zss/jsonschema/jsonschema.go
  • pkgs/zss/jsonschema/jsonschema_test.go
  • pkgs/zss/jsonschema/shared/schema.go
  • pkgs/zss/schema/zss_document_schema.go
  • pkgs/zss/toZSS_kinds_test.go
  • pkgs/zss/toZSS_metadata_meta_test.go
  • pkgs/zss/toZSS_metadata_nometa_test.go
  • pkgs/zss/toZSS_processors_test.go
  • pkgs/zss/toZSS_serialization_meta_test.go
  • pkgs/zss/toZSS_struct_shape_test.go
  • pkgs/zss/toZSS_test.go
  • pkgs/zss/toZSS_type_metadata_test.go
  • recursive.go
  • schemas/zss/0.0.1/schema.json
  • toZSS.go

Comment thread pkgs/zss/jsonschema/draft2020_12/jsonschema.go
Comment thread pkgs/zss/jsonschema/draft2020_12/jsonschema.go
Comment thread pkgs/zss/toZSS_processors_test.go
Comment thread docs/static/zss/0.0.1/schema.json Outdated
Comment thread toZSS.go
@Oudwins Oudwins changed the title wp feat: zss, zss to json schema and json schema for zss Jun 8, 2026
@Oudwins

Oudwins commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@greptile please review again

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Makefile`:
- Around line 18-19: The schema-gen Make target is invoking
cmd/zssschema-gen/main.go without the required version flag, so update the
schema-gen recipe to pass the schema version argument expected by the generator.
Use the schema generator entrypoint in cmd/zssschema-gen/main.go and ensure make
schema-gen supplies -version so it can regenerate
docs/static/zss/<version>/schema.json instead of failing immediately.

In `@toZSS.go`:
- Around line 116-122: The field lookup in toZSS should resolve struct tag
aliases before trying ASCII case guessing. Update the field-resolution logic
around t.FieldByName so it first checks tags such as json/zog against the
incoming key (for example full_name -> FullName), then falls back to the
existing first-letter capitalization behavior. Keep the fix localized to the
field lookup path used by FieldMeta so downstream schema conversion receives the
correct field metadata.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ade2812b-0274-4b5c-8987-cccfefe653b3

📥 Commits

Reviewing files that changed from the base of the PR and between 0657aca and 59838cc.

📒 Files selected for processing (8)
  • Makefile
  • cmd/zssschema-gen/main.go
  • cmd/zssschema-gen/main_test.go
  • docs/static/zss/0.0.1/schema.json
  • pkgs/zss/core/zss_structures.go
  • pkgs/zss/jsonschema/draft2020_12/jsonschema.go
  • pkgs/zss/jsonschema/jsonschema_test.go
  • toZSS.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkgs/zss/core/zss_structures.go
  • cmd/zssschema-gen/main_test.go
  • pkgs/zss/jsonschema/jsonschema_test.go
  • cmd/zssschema-gen/main.go
  • pkgs/zss/jsonschema/draft2020_12/jsonschema.go

Comment thread Makefile
Comment thread toZSS.go
@Oudwins
Oudwins merged commit b486cb1 into master Jul 5, 2026
17 checks passed
@Oudwins
Oudwins deleted the feat/zss branch July 5, 2026 16:41
@coderabbitai coderabbitai Bot mentioned this pull request Jul 11, 2026
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