-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feature(jackson3) add jackson3 support for spring generator #22854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feature(jackson3) add jackson3 support for spring generator #22854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 issues found across 87 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/README.md">
<violation number="1" location="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/README.md:17">
P2: README example passes a WebClient to HttpInterfacesAbstractConfigurator, but the generated configurator expects a RestClient, so the example will not compile.</violation>
</file>
<file name="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/src/main/java/org/openapitools/api/FakeApi.java">
<violation number="1" location="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/src/main/java/org/openapitools/api/FakeApi.java:213">
P2: MultipartFile parameter is declared with @RequestPart, but the request content type is set to application/x-www-form-urlencoded. File uploads in Spring use multipart/form-data, so this mismatch prevents sending the binary part correctly and can lead to 415/empty file data.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache:134">
P2: Jackson 3 dependencies are added without a managed version; when useJackson3 is enabled the generated POM lacks a version or BOM for tools.jackson.*, which will cause Maven build failures.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/httpInterfacesConfiguration.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/httpInterfacesConfiguration.mustache:41">
P2: Non-reactive template now requires RestClient (Spring 6.1+), breaking generated code for Spring Boot 3.0/3.1 users without a fallback or version guard.</violation>
</file>
<file name="CONTRIBUTING.md">
<violation number="1" location="CONTRIBUTING.md:15">
P3: Introduced typo in contribution guideline text (“staonrt a discussi”), which should remain “start a discussion.”</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom4.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom4.mustache:98">
P2: `jackson-databind-nullable` is a Jackson 2 module (`com.fasterxml.jackson`) but is always added even when `useJackson3` is enabled, which uses `tools.jackson` artifacts. This mixes incompatible Jackson versions and prevents registering the nullable module with a Jackson 3 `ObjectMapper`.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache:58">
P2: The template enables servlet (`spring-boot-starter-web`) when `reactive=false`, but generated code uses `RestClient`, which was introduced in Spring Framework 6.1 (Boot 3.2+). The default parent remains Spring Boot 3.1.3 (Spring 6.0), so non-reactive generated projects will fail to compile due to missing `RestClient`.</violation>
</file>
<file name="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/src/main/java/org/openapitools/api/StoreApi.java">
<violation number="1" location="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/src/main/java/org/openapitools/api/StoreApi.java:39">
P2: `orderId` uses `String` for DELETE but `Long` for GET on the same `{order_id}` path variable, creating an inconsistent API contract for the same endpoint and conflicting with the Javadoc’s integer ID expectation.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb4.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb4.mustache:234">
P2: jackson-databind-nullable 0.2.8 is a Jackson 2 module but is always added even in useJackson3 mode, leading to Jackson 2/3 API incompatibility when registering JsonNullableModule.</violation>
</file>
<file name="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/pom.xml">
<violation number="1" location="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/pom.xml:63">
P1: Missing version for tools.jackson.datatype:jackson-datatype-jsr310; without dependencyManagement this will fail Maven resolution.</violation>
<violation number="2" location="samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/pom.xml:67">
P2: jackson-databind-nullable 0.2.8 is a Jackson 2 module (com.fasterxml.jackson.*) and will not integrate with Jackson 3 (tools.jackson.*) ObjectMapper used by this jackson-3 sample, causing incompatible dependencies.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache:184">
P2: Jackson 3 (`tools.jackson.*`) dependencies are added without versions; Spring Boot 3.1.3 only manages `com.fasterxml.jackson.*`, so `useJackson3` builds will fail to resolve these artifacts unless versions/BOM are added.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache:198">
P3: Unreachable mustache block: this dependency is wrapped in {{^useJackson3}}, so the inner {{#useJackson3}} groupId section can never render. This dead code is confusing and likely a logic oversight.</violation>
<violation number="2" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache:199">
P2: Jackson 3 dependencies are added without versions, but Spring Boot 2.7.x parent does not manage tools.jackson.* artifacts. Projects generated with useJackson3 will fail Maven resolution with missing version errors.</violation>
<violation number="3" location="modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache:288">
P2: When `useJackson3` is enabled, the template switches core Jackson dependencies to `tools.jackson.*` but still includes `jackson-databind-nullable` 0.2.8 (a Jackson 2 `com.fasterxml.jackson` module). This creates an incompatible dependency mix and will fail when trying to register the JsonNullable module with a Jackson 3 ObjectMapper.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/pom.xml
Show resolved
Hide resolved
samples/client/petstore/spring-http-interface-noResponseEntity-jackson-3/README.md
Outdated
Show resolved
Hide resolved
...ng-http-interface-noResponseEntity-jackson-3/src/main/java/org/openapitools/api/FakeApi.java
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache
Outdated
Show resolved
Hide resolved
...in/resources/JavaSpring/libraries/spring-http-interface/httpInterfacesConfiguration.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache
Outdated
Show resolved
Hide resolved
|
I wonder what use the @Configuration
class ApiClientConfig {
@Bean
PetApi petApi(WebClient webClient) {
return HttpServiceProxyFactory
.builder(WebClientAdapter.forClient(webClient))
.build()
.createClient(PetApi.class);
}
}I mean - the point of the declarative interface is that it should be client-agnostic. So one can grab it and instantiate their own client with it regardless whether they use WebClient, RestClient or RestTemplate... In my opinion it just makes maintenance of this generator much more costly than it needs to be for a very little benefit. And it is not flexible enough. Often one wants to use a different WebClient/RestClient per interface. And this generated one does not seem to offer that. |
616c731 to
d76e18d
Compare
* add 'useJackson3' option * add 'useSpringBoot4' option * add support for RestClient in spring-http-interfaces See OpenAPITools#22294
d76e18d to
07a641f
Compare
|
@Picazsoo I juste adapted the existing code and did not want to bring toomuch change in this, quite already, big change 😅 In my case I only generates interface and model, and generates client in my code with interceptors, url and so on... |
|
Yes, I understand you are simply working with the current state and bringing it up to date. No problem with that (-: ! |
Description
This pull request aim to provide jackson 3 support for spring generator. as it is the recommanded way for any springboot 4 project (see #22294 )
add 'useJackson3' option
I added this option only at the spring generator level, so as not to make it visible for all java generators (as I caught sight of it when a I generated the documentation).
I use this option so as to import the right import of
JsonDeserializeas this import is added by the code and not at template level.I added tests for
SpringCodegenin order to test that the jackson 3 import is well added.add support for RestClient in spring-http-interfaces
The client for spring http interface should use
RestClientinstead ofWebClientin non reactive mode; theWebClientis the reactive implementation of spring clients. AsRestClientwas added in spring6.1/ spring boot3.2, I updated thepom-sb3dependencies to3.2.0. Also updated spring cloud to2023.0.0for compability with spring boot3.2(see compatibility matrix)add 'useSpringBoot4' option
I willingly introduced this option in order to limitate, for spring generator, the use of jackson 3 only when using a spring boot 4 project.
PR checklist
Summary by cubic
Adds Jackson 3 support to the Spring generator with new useJackson3 and useSpringBoot4 options, and switches non‑reactive Spring HTTP interface clients to RestClient. Also adds Spring Boot 4 POM templates and updates docs, tests, and samples.
New Features
Migration
Written for commit 07a641f. Summary will update on new commits.