Skip to content

feat: add JSON Schema export functionality#532

Open
doubledare704 wants to merge 3 commits intoalecthomas:masterfrom
doubledare704:feature/json-schema-export
Open

feat: add JSON Schema export functionality#532
doubledare704 wants to merge 3 commits intoalecthomas: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

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 efd7df1 to d8092eb Compare August 31, 2025 08:48
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

1 participant