feature/default-values-support#1
Open
dordzhiev wants to merge 3 commits into
Open
Conversation
added 2 commits
September 30, 2025 10:14
This commit implements foundational default value functionality for the Dart renderer, supporting primitive types and enums but not complex objects.
This commit extends the existing default value functionality to support complex object types with nested structures, completing the implementation of default values for all Dart data types.
65b26bb to
891201b
Compare
- Add default values documentation to README and FAQ - Clarify Dart-only support for default values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Default Values Support for Dart Renderer
Summary
This PR implements comprehensive default value support for the Dart renderer in quicktype, allowing JSON schemas with
defaultproperties to generate Dart classes with proper default value initialization.What's New
Core Features
defaultproperties are now parsed and stored in the type systemTechnical Implementation
Type System Extensions:
ClassPropertyto store default valuesTypeBuilderto handle default value parametersJSON Schema Integration:
JSONSchemaInputto extractdefaultproperties from schema definitionsDart Renderer Enhancements:
_formatDefaultValue()method for type-safe default value formatting@Default()annotationsFiles Changed
Core Type System
packages/quicktype-core/src/Type/Type.ts- Extended ClassProperty with default value supportpackages/quicktype-core/src/Type/TypeBuilder.ts- Updated property creation methodspackages/quicktype-core/src/Type/TypeGraphUtils.ts- Enhanced type utilitiesInput Processing
packages/quicktype-core/src/input/JSONSchemaInput.ts- Added default value extraction from JSON Schemapackages/quicktype-core/src/input/Inference.ts- Updated inference logicDart Renderer
packages/quicktype-core/src/language/Dart/DartRenderer.ts- Major enhancements (203 lines added)@Default()annotationsGraph Processing
packages/quicktype-core/src/GraphRewriting.ts- Updated graph rewriting logicpackages/quicktype-core/src/UnifyClasses.ts- Enhanced class unificationpackages/quicktype-core/src/rewrites/ReplaceObjectType.ts- Updated object type replacementpackages/quicktype-core/src/rewrites/ResolveIntersections.ts- Enhanced intersection resolutionTesting
test/inputs/schema/default-values.schema- Test schema with various default value typestest/inputs/schema/default-values.1.json- Test data for validationExample Usage
Input JSON Schema:
{ "type": "object", "properties": { "name": { "type": "string", "default": "John Doe" }, "age": { "type": "integer", "default": 25 }, "isActive": { "type": "boolean", "default": true }, "tags": { "type": "array", "items": {"type": "string"}, "default": ["default", "tag"] } } }Generated Dart Code:
Freezed Support:
Key Features
Supported Default Value Types
string,number,booleanarray(generates empty list[])nullhandlingAdvanced Features
@Default()annotations for Freezed classesTesting
The implementation includes comprehensive test cases covering:
Impact
Breaking Changes
None - This is a purely additive feature that maintains backward compatibility.
Documentation
Ready for Review