Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ This project does not adhere to [Semantic Versioning](https://semver.org/) and m

- `idn-hostname` rejects a trailing label separator, such as `example.`, `example。` or `a..`. Released versions up to 3.0.9 accepted any number of them, so a fully-qualified name written with the root dot, such as `example.`, now fails; strip the trailing dot before validating such input. This follows the JSON-Schema-Test-Suite and matches `hostname`, which already rejects a trailing dot.
- `uri-template` limits literals to the characters RFC 6570 section 2.1 allows. A space or a backslash (`a b`, `a\b`), C1 control characters, lone surrogates, noncharacters, U+FFF0 to U+FFFD and U+E0000 to U+E0FFF are now rejected in a literal; 3.0.9 and earlier accepted any character other than ASCII controls and ``" < > ^ ` { | }``. The apostrophe is still accepted, as in the JSON-Schema-Test-Suite. The vendored `uri-template.json` suite files are updated to the current JSON-Schema-Test-Suite.
- The value of an annotation is now the value the keyword holds, for every JSON value type. Boolean, array and null values used to be dropped, so a keyword whose value was a boolean, an array or `null` did not appear in the collected annotations at all. This applies to every annotation keyword, including the ones created for `readOnly` and `writeOnly`, for keywords that are not in the dialect, such as unknown keywords and root level fields, and for `deprecated`, `default`, `examples`, `example`, `xml` and `contentSchema`. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)
- `RequiredValidator.getFieldKeyword` is now called for each required property and keyword on the first validation, whether or not a policy is enabled, and the result is cached; previously it ran only when a policy was enabled and the property was missing during validation. It is deprecated for removal. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)
- The generic return type of `Annotation.getValue()` now has a wider set of values. Existing code such as `String s = annotation.getValue()` still compiles but now throws `ClassCastException` where the value is not a string; read the value as the type the keyword holds. An object, an array or a null is returned as a fresh copy of the schema node, so mutating it does not change the cached schema. A null value is reported as a `NullNode` rather than as the Java null that means there is no value. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)

### Added

- `readOnly` and `writeOnly` are reported as annotations at the instance location they apply to when annotation collection is enabled. This is the keyword value in the schema; it has nothing to do with the `readOnly` and `writeOnly` execution config options. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)
- `Annotation.isSchemaNodeAnnotation()` and `Annotation.Builder.schemaNodeAnnotation(boolean)` report whether an annotation is the raw value of its schema node rather than an applicator result. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)

### Changed

- The `readOnly` and `writeOnly` execution policies no longer report an error when the keyword value is the boolean `false`, because the error contradicts the annotation reported for that value. This applies whether annotation collection is enabled or not. Every other value still reports the error, including `true` and a value that is not a boolean, so nothing that was accepted before is now rejected. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)
- `hostname` rejects names longer than 253 characters.
- `hostname` checks a label that starts with `xn--`, in any case, as an A-label. It must be at most 63 characters of Punycode that encodes back to itself, and its U-label must pass the IDNA2008 rules listed below. `xn--X`, `xn--hello-txk` and `xn--1-0hc` (U-label `1א`, which breaks the RFC 5893 Bidi Rule) are now rejected; before, any LDH label passed. The Bidi Rule applies within each A-label only: the other labels stay RFC 1123 LDH labels, so `3com.xn--mgbaam7a8h` remains valid.
- `idn-hostname` decodes A-labels with an RFC 3492 Punycode decoder instead of `java.net.IDN` (IDNA2003). A-labels with characters IDNA2008 allows in context, such as U+00DF, U+03C2, U+200C and U+200D, are accepted when the RFC 5892 rules allow them. A-labels are case-insensitive.
Expand All @@ -31,10 +40,13 @@ This project does not adhere to [Semantic Versioning](https://semver.org/) and m
- `idn-hostname` does not apply UTS 46 mapping.
- Removed the unused `UnicodeDatabase.isGreek`, `isHebrew` and `isKatakana`, which tested code blocks rather than scripts.
- Updated the vendored `hostname.json` and `idn-hostname.json` suite files to the current JSON-Schema-Test-Suite, including `draft-next`. Cases that need UTS 46 mapping are disabled with a reason.

### Fixed

- `uri-template` no longer throws `StackOverflowError` on long templates, such as a 5,000-character literal or an expression with a 1,000-character variable name. Runs of literal and variable-name characters are matched without recursion.
- Collecting annotations no longer changes the result of `unevaluatedItems` or `unevaluatedProperties` when an annotation keyword shares a name with an applicator the validator consumes. An annotation collected from a schema node now reports that it is not an applicator result, so an unknown keyword, a root field of a document container, a keyword a dialect registers as an `AnnotationKeyword`, or `readOnly`/`writeOnly` cannot mark items or properties as evaluated. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)
- Prevent descendant discriminator state from leaking between `oneOf` and `anyOf` branches in OpenAPI 3.0 and 3.1. [#1378](https://github.com/networknt/json-schema-validator/issues/1378)
- The `required` keyword no longer demands a `readOnly` or `writeOnly` property that the corresponding policy would assert for. It follows the policy rule, so a value that is not the boolean `false` exempts the property; a value that is not a boolean is no longer passed to `booleanValue()`, which threw `JsonNodeException`. Both policies are honoured when both are enabled. The exemption is decided from the keyword declared directly on the property schema in `properties`; a `readOnly` or `writeOnly` reached through `$ref` or `allOf` is not resolved into the property schema, so such a property is still required and still reports the policy error. The dialect is not consulted either: Draft 4 and 6 do not define `readOnly` or `writeOnly`, yet a property that declares one is still exempt from `required` there, which a test pins. [#1376](https://github.com/networknt/json-schema-validator/pull/1376)

## 3.0.9- 2026-11-03

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,13 @@ The following is sample output from the Hierarchical format.
| `locale` | The locale to use for generating messages in `Error`. Note that this value is copied from `SchemaRegistryConfig` for each execution. | `Locale.getDefault()` |
| `failFast` | Whether to return failure immediately when an assertion is generated. Note that this value is copied from `SchemaRegistryConfig` for each execution but is automatically set to `true` for the Boolean and Flag output formats. | `false` |
| `formatAssertionsEnabled` | The default is to generate format assertions from Draft 4 to Draft 7 and to only generate annotations from Draft 2019-09. Setting to `true` or `false` will override the default behavior. | `null` |
| `readOnly` | Used to indicate that the property should not be sent as part of the request payload, but only in the response payload. This affects the `readOnly` keyword used for the OpenAPI dialect. | `null` |
| `writeOnly` | Used to indicate that the property should not be sent as part of the response payload, but only in the request payload. This affects the `writeOnly` keyword used for the OpenAPI dialect. | `null` |
| `readOnly` | Used to indicate that the property should not be sent as part of the request payload, but only in the response payload. See the note on the two policies below this table. | `null` |
| `writeOnly` | Used to indicate that the property should not be sent as part of the response payload, but only in the request payload. See the note on the two policies below this table. | `null` |
| `maxEvaluationSteps` | Maximum admitted schema-entry and keyword-dispatch steps per validation or walk execution. Zero means unlimited; negative values are rejected. See [Validation execution limits](doc/validation-execution-limits.md). | `0` |
| `maxEvaluationDepth` | Maximum simultaneously active schema evaluation frames, including the root, references, and schema wrappers. Zero means unlimited; negative values are rejected. | `0` |

**The `readOnly` and `writeOnly` policies.** Both apply to the keyword in Draft 7 and later, including the OpenAPI 3.0 and 3.1 dialects. When a policy is `true`, the keyword reports an error unless its value is the boolean `false`. A property whose keyword the policy asserts for (any value but the boolean `false`) is also exempt from `required`, whether or not the dialect defines the keyword, but only a declaration directly on the property schema is seen, not one reached through `$ref` or `allOf`.

### Schema Registry Configuration

| Name | Description | Default Value |
Expand Down
4 changes: 2 additions & 2 deletions doc/error-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ The built-in formats have their own key: `format.date`, `format.date-time`, `for
| `dependentRequired` | `dependentRequired` | A property is present but a property it depends on is missing. Draft 2019-09 and later. | `{0}` the missing property, `{1}` the property that is present | `property` | `has a missing property '{0}' which is dependent required because '{1}' is present` |
| `dependencies` | `dependencies` | A property is present but a property listed for it in `dependencies` is missing. Draft 7 and earlier. | `{0}` the list of dependencies | `property` | `has an error with dependencies {0}` |
| `notAllowed` | `notAllowed` | A property listed in `notAllowed` is present. Only in dialects that add `notAllowed`. | `{0}` the property name | `property` | `property '{0}' is not allowed but it is in the data` |
| `readOnly` | `readOnly` | A `readOnly` value is present and the execution config sets `readOnly(true)`. | none | | `is a readonly field, it cannot be changed` |
| `writeOnly` | `writeOnly` | A `writeOnly` value is present and the execution config sets `writeOnly(true)`. | none | | `is a write-only field, it cannot appear in the data` |
| `readOnly` | `readOnly` | A `readOnly` value is present, the value is not the boolean `false`, and the execution config sets `readOnly(true)`. | none | | `is a readonly field, it cannot be changed` |
| `writeOnly` | `writeOnly` | A `writeOnly` value is present, the value is not the boolean `false`, and the execution config sets `writeOnly(true)`. | none | | `is a write-only field, it cannot appear in the data` |

### Combining schemas

Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/networknt/schema/ExecutionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,24 @@ public Predicate<String> getAnnotationCollectionFilter() {
}

/**
* Returns the value of the read only flag.
* Returns the read only policy.
* <p>
* See {@link BuilderSupport#readOnly(Boolean)} for what the policy does.
*
* @return the value of read only flag or null if not set
* @see BuilderSupport#readOnly(Boolean)
*/
public Boolean getReadOnly() {
return this.readOnly;
}

/**
* Returns the value of the write only flag.
* Returns the write only policy.
* <p>
* See {@link BuilderSupport#writeOnly(Boolean)} for what the policy does.
*
* @return the value of the write only flag or null if not set
* @see BuilderSupport#writeOnly(Boolean)
*/
public Boolean getWriteOnly() {
return this.writeOnly;
Expand Down Expand Up @@ -254,6 +260,14 @@ protected Builder self() {

/**
* Builder for {@link ExecutionConfig}.
* <p>
* The {@code readOnly} and {@code writeOnly} policies apply to the keyword in
* Draft 7 and later, including the OpenAPI 3.0 and 3.1 dialects. When a policy is
* true, the keyword reports an error unless its value is the boolean false. A
* property whose keyword the policy asserts for (any value but the boolean false)
* is also exempt from required, whether or not the dialect defines the keyword,
* although only a declaration directly on the property schema is seen, not one
* reached through $ref or allOf.
*/
public static abstract class BuilderSupport<T> {
protected Locale locale = Locale.ROOT;
Expand Down Expand Up @@ -336,11 +350,25 @@ public T failFast(boolean failFast) {
return self();
}

/**
* Sets the read only policy. See {@link BuilderSupport} for what the policy does.
*
* @param readOnly the read only policy, null clears it so that the getter returns
* null
* @return the builder
*/
public T readOnly(Boolean readOnly) {
this.readOnly = readOnly;
return self();
}

/**
* Sets the write only policy. See {@link BuilderSupport} for what the policy does.
*
* @param writeOnly the write only policy, null clears it so that the getter
* returns null
* @return the builder
*/
public T writeOnly(Boolean writeOnly) {
this.writeOnly = writeOnly;
return self();
Expand Down
Loading