aceViilee opened a new issue, #9195:
URL: https://github.com/apache/camel-quarkus/issues/9195

   ### Bug description
   
   With `camel-quarkus-openapi-java` 3.33.2 (swagger-core-jakarta 2.2.36, 
Jackson 2.21, Quarkus 3.33.3, Mandrel 23.1-jdk-21 builder image) and a REST DSL 
with an `apiContextPath`, every native start logs, once per resolved model 
type, while `RestOpenApiProcessor.doInit` renders the document:
   
   ```
   WARN  io.swagger.v3.core.jackson.ModelResolver: jackson 
BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate 
result, please update jackson to 2.9+
   ERROR io.swagger.v3.core.jackson.ModelResolver: Neither 
'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson 
BeanDescription. Please verify your Jackson version.
   ```
   
   The JVM run of the same application logs neither.
   
   `ModelResolver.findJsonValueType` calls its private `invokeMethod(beanDesc, 
"findJsonValueAccessor")`, which does `BeanDescription.class.getMethod(name)` 
with the name passed as a parameter, so the image builder cannot fold the 
lookup, and nothing registers the method for reflection.
   
   Besides the log lines, the generated document differs: a class (not an enum) 
whose JSON form is a `@JsonValue` accessor is rendered as `type: string` on the 
JVM, but in native mode as an object schema of its remaining bean properties.
   
   This looks like a regression from 3.26.0: #6593 (commit 
d25a9ed5bfc81ca5db6e2c018c2e7b9fa2b05efa) removed `ModelResolverSubstitutions`, 
whose `findJsonValueType` made the same lookup with a constant method name, 
which the image builder can fold. swagger-core itself (since the Jackson 2.18 
change, swagger-api/swagger-core#4755, and unchanged on master) passes the name 
through `invokeMethod`. Going by the sources, neither `SupportSwaggerProcessor` 
nor `OpenApiJavaProcessor` registers the method in 3.39.0 or on main.
   
   **Steps to reproduce**
   
   1. A route builder with 
`restConfiguration().component("platform-http").apiContextPath("/openapi.json")`
 and a `rest()` verb with `.outType(...)` of a plain model class.
   2. Build with `-Dnative` and start the binary: one WARN and one ERROR per 
model type at startup.
   3. Optionally add a verb whose `outType` is a class like the one below and 
compare `/openapi.json` between JVM and native mode:
   
   ```java
   @RegisterForReflection
   public class ProbeValue {
       private final String code;
       public ProbeValue(String code) { this.code = code; }
       @JsonValue
       public String getCode() { return code; }
       public String getExtra() { return "extra"; }
   }
   ```
   
   JVM: the response schema is `{"type": "string"}`. Native: `{"$ref": 
"#/components/schemas/ProbeValue"}` with `ProbeValue` as `{"type": "object", 
"properties": {"extra": {"type": "string"}}}`.
   
   **Workaround / suggested fix**
   
   Registering 
`com.fasterxml.jackson.databind.BeanDescription#findJsonValueAccessor()` for 
reflection fixes both (measured: no ModelResolver lines, and the native 
document equals the JVM's, the `@JsonValue` class included). We ship it for now 
as a `reflect-config.json` in a shared library:
   
   ```json
   [
     {
       "condition": { "typeReachable": 
"io.swagger.v3.core.jackson.ModelResolver" },
       "name": "com.fasterxml.jackson.databind.BeanDescription",
       "methods": [ { "name": "findJsonValueAccessor", "parameterTypes": [] } ]
     }
   ]
   ```
   
   In the extension it could be a `ReflectiveMethodBuildItem` for that method 
in `SupportSwaggerProcessor`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to