Skip to content

feat: add uuid, date, date-time, uri format validators#96

Merged
nic-6443 merged 4 commits intoapi7:masterfrom
jarvis9443:feat/add-format-validators
Apr 21, 2026
Merged

feat: add uuid, date, date-time, uri format validators#96
nic-6443 merged 4 commits intoapi7:masterfrom
jarvis9443:feat/add-format-validators

Conversation

@jarvis9443
Copy link
Copy Markdown
Contributor

@jarvis9443 jarvis9443 commented Apr 21, 2026

Add PCRE regex patterns for uuid, date, date-time, and uri formats to the reg_map table, enabling format validation for these commonly used JSON Schema formats.

Changes:

  • lib/jsonschema.lua: added 4 new format regex entries to reg_map, updated error message from "address" to "format"
  • spec/extra/format.json: added test cases for each new format (valid/invalid/non-string inputs, plus URI edge cases for whitespace and empty path)
  • .github/workflows/ci.yml: updated runner from ubuntu-18.04 to ubuntu-22.04, modernized actions and GPG key handling

All existing tests pass locally.

Summary by CodeRabbit

  • New Features

    • Added validation for UUID, date, date-time, and URI formats with clearer format-failure messages.
  • Tests

    • Added comprehensive tests covering valid and invalid UUID, date, date-time, and URI cases, including variants and edge cases.
  • Chores

    • Modernized CI workflow environment and package installation steps to update build tooling and dependencies.

Add PCRE regex patterns for uuid, date, date-time, and uri formats
to the reg_map table. Also update the error message from "address"
to "format" since these new formats are not addresses.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8178328f-b8f6-47cf-ab56-e2b64a9b470c

📥 Commits

Reviewing files that changed from the base of the PR and between 17935bd and ff996f5.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml

📝 Walkthrough

Walkthrough

Added regex-based format validators for uuid, date, date-time, and uri to the JSON Schema validator and updated its format error message. Added corresponding tests for these formats and updated the CI workflow to use Ubuntu 22.04, newer actions, and an apt-based OpenResty installation.

Changes

Cohort / File(s) Summary
Format validator implementation
lib/jsonschema.lua
Added reg_map entries for uuid, date, date-time, and uri to validate schema.format via regex; updated the format-validation message to "expect valid %s format but got: " in the reg_map[schema.format] branch.
Format test specifications
spec/extra/format.json
Appended test groups for uuid, date, date-time, and uri formats covering multiple valid and invalid cases (case variants, timezone/fractional seconds, date boundaries, URIs with various schemes, and non-string inputs).
CI workflow
.github/workflows/ci.yml
Switched CI runner to ubuntu-22.04, updated actions/checkout to @v4, bumped leafo/gh-actions-lua to v10, added libpcre3-dev, and changed OpenResty installation to use a dearmored GPG key with a signed-by apt source and apt-get installation steps.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding format validators for uuid, date, date-time, and uri to the JSON Schema implementation.
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.
E2e Test Quality Review ✅ Passed PR adds format validators (uuid, date, date-time, uri) with 184 lines of comprehensive JSON test cases covering valid/invalid inputs and boundary conditions, exercising the complete schema validation pipeline end-to-end through schema.validate().
Security Check ✅ Passed Security analysis of regex patterns, error handling, CI configuration, and test data reveals no vulnerabilities, credential exposure, or sensitive information disclosure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/jsonschema.lua`:
- Line 593: The current ["uri"] pattern in lib/jsonschema.lua is too permissive
(allows whitespace) and rejects scheme-only URIs like "foo:". Replace the
pattern string for the "uri" key with a hardened regex that forbids whitespace
after the colon but permits an empty-path scheme, for example use
^[a-zA-Z][a-zA-Z0-9+\-.]*:(?:\S.*)?$ in place of the existing
^[a-zA-Z][a-zA-Z0-9+\-.]*:.+$ so the "uri" validator disallows whitespace-only
tails while accepting "scheme:" forms.

In `@spec/extra/format.json`:
- Around line 150-186: The test suite under the "tests" array for date/date-time
currently only checks format and simple numeric bounds; add calendar-edge
negative cases so regex-only validators fail correctly — extend the tests (near
existing entries like "invalid date: day 32" and "invalid date: month 13") to
include non-leap-year Feb 29 (e.g., "2023-02-29"), invalid Feb 30/31 (e.g.,
"2024-02-30", "2024-02-31"), months with 30 days receiving 31 (e.g.,
"2024-04-31", "2024-06-31", "2024-09-31", "2024-11-31"), and any invalid
date-time timestamps (e.g., "2024-02-29T12:00:00Z" for non-leap year) so that
the test descriptions and data fields (the entries in the "tests" array) assert
valid: false for these calendar-edge cases.
- Around line 242-283: Add two boundary tests to the existing "tests" array: one
checking that URIs containing whitespace are rejected (e.g., a test object with
"description": "invalid URI: contains whitespace", "data": "http://exa
mple.com", "valid": false) and one checking the empty-path case with a scheme
and colon (e.g., "description": "valid URI: empty path (foo:)", "data": "foo:",
"valid": true); place these new objects alongside the other test entries so the
suite exercises both whitespace handling and the scheme-with-empty-path case.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a0e1c7f1-4d52-4a55-ad98-0cce286dbd05

📥 Commits

Reviewing files that changed from the base of the PR and between a55072d and d41c20e.

📒 Files selected for processing (2)
  • lib/jsonschema.lua
  • spec/extra/format.json

Comment thread lib/jsonschema.lua
Comment thread lib/jsonschema.lua Outdated
Comment thread spec/extra/format.json
Comment thread spec/extra/format.json
Reject whitespace in URIs by using [^\s]* instead of .+, and accept
empty-path URIs like "foo:". Add test cases for these edge cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread spec/extra/format.json
- ubuntu-18.04 runners are no longer available on GitHub Actions
- Update checkout to v4, lua action to v10
- Use gpg keyring instead of deprecated apt-key
- Add libpcre3-dev dependency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/ci.yml:
- Line 32: The CI step that runs "sudo apt-get install -y build-essential
libncurses5-dev libreadline-dev libssl-dev perl libpcre3-dev" should be preceded
by an index refresh; update the run command so it calls "sudo apt-get update"
(or "apt-get update" with sudo) before the first apt-get install invocation in
that step to ensure package lists are current and avoid intermittent CI
failures.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 235243d2-4629-464e-ba98-9a8d93e19832

📥 Commits

Reviewing files that changed from the base of the PR and between d41c20e and 17935bd.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • lib/jsonschema.lua
  • spec/extra/format.json
✅ Files skipped from review due to trivial changes (1)
  • spec/extra/format.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/jsonschema.lua

Comment thread .github/workflows/ci.yml Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nic-6443 nic-6443 merged commit 711a61b into api7:master Apr 21, 2026
3 checks passed
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