Skip to content

fix: replace java-json-tools to fix security issues - #2416

Merged
daniel-kmiecik merged 4 commits into
v1from
remove-java-json-tools
Nov 4, 2026
Merged

daniel-kmiecik merged 4 commits into
v1from
remove-java-json-tools

Conversation

@daniel-kmiecik

@daniel-kmiecik daniel-kmiecik commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Thank you for contributing to swagger-parser!

Please fill out the following checklist to help us review your PR efficiently.


Description

This pull request modernizes the swagger-compat-spec-parser module by removing legacy dependencies and updating code to use standard Jackson APIs and internal utilities. The changes primarily focus on replacing the deprecated com.github.fge JSON libraries with Jackson's standard classes, simplifying the codebase and improving maintainability. Additionally, a new documentation file, CLAUDE.md, has been added to provide comprehensive guidance for contributors and maintainers.

Dependency and Code Modernization:

  • Replaced the com.github.java-json-tools:json-schema-validator and related com.github.fge libraries with com.networknt:json-schema-validator and removed unused dependencies such as rhino and json-patch in pom.xml.
  • Updated all usages of com.github.fge.jackson.jsonpointer.JsonPointer to use Jackson's com.fasterxml.jackson.core.JsonPointer and updated code to use the .compile() method for pointer creation.
  • Replaced JacksonUtils.newMapper() with JacksonSupport.newMapper() for object mapper instantiation throughout the migrator and utility classes, and removed imports of unused or deleted classes.
  • Updated resource loading from JsonLoader.fromResource to JacksonSupport.fromResource and removed exception handling for JsonPatchException where no longer needed, simplifying patch application logic.

Documentation:

  • Added a new CLAUDE.md file with detailed build, test, branching, architecture, and release process instructions to help contributors and maintainers understand and work with the codebase.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The JSON patch assertions can pass despite incorrect object member names because TestNG compares JsonNode values as iterables, and the guide includes module commands that fail in this checkout.

2 open issues
What changed in this PR

This PR replaces legacy java-json-tools dependencies in the Swagger compatibility parser with NetworkNT validation, standard Jackson APIs, and internal utilities to address security concerns.

Changes:

  • Replaces schema validation, JSON Pointer handling, and JSON Patch dependencies.
  • Adds patch and validation tests, updates existing tests, and adds reference fixtures.
  • Adds contributor documentation covering builds and architecture.
File Description
modules/​swagger-parser/​src/​test/​resources/​reusableParametersWithExternalRef.json Repoints the external parameter reference to a pinned GitHub resource.
modules/​swagger-parser-v3/​src/​test/​resources/​issue-2217/​pagination.yaml Adds a pagination schema fixture.
modules/​swagger-parser-v3/​src/​test/​resources/​issue-2217/​main.yaml Adds a fixture referencing external schemas and responses.
modules/​swagger-parser-v3/​src/​test/​resources/​issue-2217/​fragments.yaml Adds shared schema and response fixtures.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​validate/​SwaggerSchemaValidatorTest.java Adapts the validation test base to NetworkNT.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​validate/​SwaggerJsonValidatorTest.java Adds validation and error-reporting tests.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​validate/​Issue1Test.java Updates validation assertions for the new API.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​transform/​util/​JsonPatchTest.java Tests supported patch operations and failure cases.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​transform/​SwaggerMigratorTest.java Uses internal Jackson helpers in migration tests.
modules/​swagger-compat-spec-parser/​src/​test/​java/​io/​swagger/​parser/​ResourceListingExtractorTest.java Uses the replacement mapper factory.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​validate/​SwaggerSchemaValidator.java Validates documents through NetworkNT schemas.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​validate/​SwaggerJsonValidator.java Converts NetworkNT errors into parser messages.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​SwaggerMigrators.java Uses internal patch and resource-loading utilities.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​SwaggerJsonSchemaFactory.java Configures NetworkNT schema loading and URI validation.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​MutableJsonTree.java Adapts tree navigation to Jackson pointers.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​JsonPatch.java Implements the patch operations required by migrators.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​JacksonSupport.java Adds mapper, formatting, and resource-loading helpers.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​APIFileDownload.java Uses the internal mapper factory.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​V11TypeMigrator.java Switches type migration to internal utilities.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​V11ResourceListingMigrator.java Uses Jackson pointers for API listings.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​V11ApiDeclarationMigrator.java Uses Jackson pointers for API declarations.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​V11AllowableValuesMigrator.java Updates allowable-value lookup and patch handling.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​ApiOperationMigrator.java Uses Jackson pointers for operations.
modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​migrate/​ApiObjectMigrator.java Updates parameter and response-message navigation.
modules/​swagger-compat-spec-parser/​pom.xml Replaces legacy dependencies and inherits the parent group ID.
CLAUDE.md Adds contributor build and architecture guidance.

Review effort: Balanced

Comment thread CLAUDE.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Malformed JSON Pointer escapes are accepted, allowing invalid patch paths to modify literal members instead of being rejected.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Reject malformed JSON Pointer escape sequences

modules/​swagger-compat-spec-parser/​src/​main/​java/​io/​swagger/​transform/​util/​JsonPatch.java:245

Jackson's JsonPointer.compile() checks the leading slash but deliberately preserves malformed escapes. As a result, a patch with path: "/a~2b" or path: "/a~" is accepted and modifies that literal member instead of rejecting an invalid RFC 6901 pointer. Please validate that every ~ is followed by 0 or 1 before compiling; validating here covers both path and from.

2 resolved since last review

Review effort: Balanced

@daniel-kmiecik
daniel-kmiecik merged commit 1c995f7 into v1 Nov 4, 2026
5 checks passed
@daniel-kmiecik
daniel-kmiecik deleted the remove-java-json-tools branch November 4, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants