Skip to content

feat: add JSON Schema export functionality - #532

Open
doubledare704 wants to merge 6 commits into
alecthomas:masterfrom
doubledare704:feature/json-schema-export
Open

doubledare704 wants to merge 6 commits into
alecthomas:masterfrom
doubledare704:feature/json-schema-export

Conversation

@doubledare704

Copy link
Copy Markdown
Contributor

Add comprehensive JSON Schema export capability to voluptuous schemas, addressing issue #408. This enables integration with modern IDEs, API documentation tools, and other validation systems.

Features:

  • Convert voluptuous schemas to JSON Schema format
  • Support for all major validators (Range, Length, Email, URL, etc.)
  • Handle composite validators (All, Any, ExactSequence)
  • Proper Required/Optional marker conversion
  • Nested object and array schema support
  • Default value handling with JSON serialization safety

API:

  • Schema.to_json_schema() method on Schema instances
  • to_json_schema() standalone function
  • Full backward compatibility maintained

Testing:

  • Comprehensive test suite with 100% coverage
  • Real-world example scenarios
  • Edge case handling
  • JSON serialization validation

Documentation:

  • Updated README with usage examples
  • Complete example script demonstrating features
  • Inline documentation and docstrings

Closes #408

@doubledare704
doubledare704 force-pushed the feature/json-schema-export branch from efd7df1 to d8092eb Compare August 31, 2025 08:48
@alecthomas

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8092eb81d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py
Comment thread voluptuous/json_schema.py
Comment thread voluptuous/json_schema.py
Add comprehensive JSON Schema export capability to voluptuous schemas,
addressing issue alecthomas#408. This enables integration with modern IDEs,
API documentation tools, and other validation systems.

Features:
- Convert voluptuous schemas to JSON Schema format
- Support for all major validators (Range, Length, Email, URL, etc.)
- Handle composite validators (All, Any, ExactSequence)
- Proper Required/Optional marker conversion
- Nested object and array schema support
- Default value handling with JSON serialization safety

API:
- Schema.to_json_schema() method on Schema instances
- to_json_schema() standalone function
- Full backward compatibility maintained

Testing:
- Comprehensive test suite with 100% coverage
- Real-world example scenarios
- Edge case handling
- JSON serialization validation

Documentation:
- Updated README with usage examples
- Complete example script demonstrating features
- Inline documentation and docstrings

Closes alecthomas#408
- Replace bare except clause with specific exception types
- Fix all 17 mypy type checking errors:
  * Add proper type annotations for Dict[str, Any]
  * Replace callable with typing.Callable
  * Fix incompatible type assignments
  * Resolve indexing operation type issues
  * Add type safety for validator method parameters
- Remove unused import (voluptuous.validators)
- Maintain full backward compatibility and functionality

All flake8 and mypy checks now pass with zero issues.
All 162 existing tests continue to pass.
@doubledare704
doubledare704 force-pushed the feature/json-schema-export branch from d8092eb to abe2173 Compare August 25, 2026 21:00
@doubledare704

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c90620865

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py
Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py Outdated
Comment thread voluptuous/json_schema.py
Comment thread voluptuous/json_schema.py Outdated

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.

export/generate json schema

2 participants