Several features were introduced in version 0.68 through various patches, here’s a recap of the most important updates in case you missed them.
Improvements in JSON Schema Generation
Handling undefined Types
The behavior of JSON Schema generation has been refined to enhance the handling of optional fields.
Previously, schemas containing undefined could lead to exceptions; now, they are treated as optional automatically.
Before Update:
After Update:
Refinements in Records
The generation of JSON schemas from records that utilize refinements has been improved to ensure error-free outputs.
Before Update:
After Update:
parseJson Schemas
Resolved an issue where JSONSchema.make improperly generated JSON Schemas for schemas defined with S.parseJson(<real schema>).
Previously, invoking JSONSchema.make on these transformed schemas produced a JSON Schema corresponding to a string type rather than the underlying real schema.
Before Update:
After Update:
New String Transformations and filters
We have introduced new transformations and filters to enhance string processing capabilities:
Transformations: Capitalize, Uncapitalize
Filters: Capitalized, Uncapitalized
Asynchronous Validation with filterEffect
The filterEffect function enhances the filter functionality by allowing the integration of effects, thus enabling asynchronous or dynamic validation scenarios.
This is particularly useful when validations need to perform operations that require side effects, such as network requests or database queries.
Example: Validating Usernames Asynchronously
Introducing ReadonlyMapFromRecord and MapFromRecord
These new functionalities provide efficient transformations between records and maps, supporting both encoding and decoding processes.
decoding
{ readonly [x: string]: VI } -> ReadonlyMap<KA, VA>
encoding
ReadonlyMap<KA, VA> -> { readonly [x: string]: VI }
Example:
Expanded extend Functionality
The extend function now supports combinations with Union, Suspend, and Refinement, broadening its applicability and flexibility.
Enhanced Struct Operations: pick and omit
These operations allow selective inclusion or exclusion of properties from structs, providing more control over schema composition.
Using pick:
The pick static function available in each struct schema can be used to create a new Struct by selecting particular properties from an existing Struct.
Using omit:
The omit static function available in each struct schema can be used to create a new Struct by excluding particular properties from an existing Struct.
New make Constructor for Class APIs
The introduction of a make constructor simplifies class instantiation, avoiding direct use of the new keyword and enhancing usability.
Example
New Customizable Parsing Options at the Schema Level
This update allows setting specific parse options at the schema level (using the parseOptions annotation), ensuring precise control over parsing behaviors throughout your schemas.
Example Configuration:
Detailed Output Explanation:
In this example:
The main schema is configured to display all errors. Hence, you will see errors related to both the d field (since it’s missing) and any errors from the a subschema.
The subschema (a) is set to display only the first error. Although both b and c fields are missing, only the first missing field (b) is reported.
Schema 0.69 release
Codemod
For some of the breaking changes, a code-mod has been released to make migration as easy as possible.
You can run it by executing:
It might not be perfect - if you encounter issues, let us know! Also make sure you commit any changes before running it, in case you need to revert anything.
Enhanced API for TaggedRequest
We’ve improved the TaggedRequest API to make it more intuitive by grouping parameters into a single object:
Before Update:
After Update:
Record Constructor Update
The Record constructor now consistently accepts an object argument, aligning it with similar constructors such as Map and HashMap:
Before Update:
After Update:
Refinement and extend Enhancements
Support for extending Schema.String, Schema.Number, and Schema.Boolean with refinements has been added:
Clarification in Naming Schemas
To improve clarity, we have renamed nonEmpty filter to nonEmptyString and NonEmpty schema to NonEmptyString.
Improved Optional and Partial APIs
We’ve refined the optional and partial APIs by splitting them into two distinct methods: one without options (optional and partial) and another with options (optionalWith and partialWith).
This change resolves issues with previous implementations when used with the pipe method: