Add JsonNullable support to JSON schema generator#6071
Open
jewoodev wants to merge 1 commit into
Open
Conversation
Recognize org.openapitools.jackson.nullable.JsonNullable<T> when generating JSON schemas for tool calling and structured output, so the wrapped type T is exposed and `null` is added to the allowed types. - Register JsonNullableSchemaModule automatically when JsonNullable is on the classpath (jackson-databind-nullable is declared as optional) - A single CustomDefinitionProvider intercepts JsonNullable<T> at any type position, covering top-level parameters as well as record/POJO fields - Unannotated JsonNullable<T> parameters and fields are treated as not-required, while explicit @ToolParam, @JsonProperty, or @Schema settings still take precedence Closes spring-projects#6046 Signed-off-by: jewoodev <jewoos15@naver.com>
eb8e543 to
4bf8699
Compare
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.
Summary
Adds
JsonNullable<T>support toJsonSchemaGenerator, so generated JSON Schemas can model values that may be omitted separately from values explicitly set tonull— for both tool inputs and typed schemas.jackson-databind-nullableis an<optional>dependency;JsonNullableSchemaModuleregisters only whenJsonNullableis on the classpath.CustomDefinitionProviderunwrapsJsonNullable<T>at any position (tool parameters and record/POJO fields) — generatingT's schema and adding"null"to the allowed types.JsonNullable<T>is treated as not required by default — at both the tool parameter and record/POJO field level — while explicit@ToolParam,@JsonProperty, or@Schemasettings still take precedence.The required default intentionally differs from the generator's
PROPERTY_REQUIRED_BY_DEFAULT = truefor the unannotated case only —JsonNullableexists precisely so a caller can omit a value, so not-required is the natural fit. Happy to switch to an explicit opt-out if you'd rather keep required-by-default for this wrapper too. The checkstyle suppression is scoped toJsonNullableSchemaModulebecause thebannedNullabilityImportsrule false-positives on theJsonNullableclass name.Testing
Added JUnit coverage in
JsonSchemaGeneratorTestsfor scalar/list/objectJsonNullable<T>at top-level parameters and record fields, plus explicit required-policy overrides../mvnw packagepasses locally.Closes #6046