Skip to content

Extract AbstractJsonSchemaGenerator to remove duplication between JsonSchemaGenerator and McpJsonSchemaGenerator#6162

Open
tzolov wants to merge 1 commit into
spring-projects:mainfrom
tzolov:refactor-json-schema-generators
Open

Extract AbstractJsonSchemaGenerator to remove duplication between JsonSchemaGenerator and McpJsonSchemaGenerator#6162
tzolov wants to merge 1 commit into
spring-projects:mainfrom
tzolov:refactor-json-schema-generators

Conversation

@tzolov
Copy link
Copy Markdown
Contributor

@tzolov tzolov commented May 26, 2026

Extract shared parameter-inspection logic into a new AbstractJsonSchemaGenerator base class.

The JsonSchemaGenerator and McpJsonSchemaGenerator generators now implement two abstract hook methods (getToolAnnotationRequired / getToolAnnotationDescription) for their respective tool annotations (@ToolParam vs @McpToolParam), while the common required-check, description-resolution, forbidAdditionalProperties, and convertTypeValuesToUpperCase logic lives in the base class.
Also fixes pre-existing Jackson 3 deprecations (isTextual → isString, asText → stringValue).

…nSchemaGenerator and McpJsonSchemaGenerator

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
@tzolov tzolov added this to the 2.0.0-RC1 milestone May 26, 2026
@tzolov tzolov requested a review from sdeleuze May 26, 2026 07:27
@sdeleuze sdeleuze modified the milestones: 2.0.0-RC1, 2.0.0-M8 May 26, 2026
@sdeleuze sdeleuze self-assigned this May 26, 2026
public final class McpJsonSchemaGenerator extends AbstractJsonSchemaGenerator {

private static final boolean PROPERTY_REQUIRED_BY_DEFAULT = true;
private static final McpJsonSchemaGenerator INSTANCE = new McpJsonSchemaGenerator();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use this kind of INSTANCE static field, looks like an anti-pattern to me and I don't understand why it is needed, could we please remove it?

* {@link JsonProperty#required()}, or {@link Schema#requiredMode()}} annotation.
*/
private static final boolean PROPERTY_REQUIRED_BY_DEFAULT = true;
private static final JsonSchemaGenerator INSTANCE = new JsonSchemaGenerator();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use this kind of INSTANCE static field, looks like an anti-pattern to me and I don't understand why it is needed, could we please remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to minimize the breaking changes. Will have another pass. Moving this to RC1

@tzolov tzolov modified the milestones: 2.0.0-M8, 2.0.0-RC1 May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants