vertx-web
vertx-web copied to clipboard
OpenAPIContract fails for JsonArray examples with ClassCastException
Version
4.4.1
Context
When I construct my OpenAPIContract using io.vertx:vertx-web-openapi-router I get a ClassCastException.
Caused by: java.lang.ClassCastException: class io.vertx.core.json.JsonArray cannot be cast to class io.vertx.core.json.JsonObject (io.vertx.core.json.JsonArray and io.vertx.core.json.JsonObject are in unnamed module of loader 'app')
at io.vertx.core.json.JsonObject.getJsonObject(JsonObject.java:566)
at io.vertx.json.schema.impl.Ref.reduce(Ref.java:292)
at io.vertx.json.schema.impl.Ref.resolveUri(Ref.java:284)
at io.vertx.json.schema.impl.Ref.lambda$resolve$7(Ref.java:121)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
at io.vertx.json.schema.impl.Ref.resolve(Ref.java:121)
at io.vertx.json.schema.impl.Ref.resolve(Ref.java:46)
at io.vertx.json.schema.impl.SchemaRepositoryImpl.resolve(SchemaRepositoryImpl.java:220)
at io.vertx.openapi.contract.OpenAPIVersion.lambda$resolve$3(OpenAPIVersion.java:76)
at io.vertx.core.impl.ContextBase.lambda$null$0(ContextBase.java:137)
at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
at io.vertx.core.impl.ContextBase.lambda$executeBlocking$1(ContextBase.java:135)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
I believe the error happens when resolving the example in my spec. The example lists an array but the implementation expects an JsonObject.
ContentListResponse:
type: array
items:
$ref: "#/components/schemas/ContentResponse"
example:
- uuid: "4fbe29c9-c69a-4572-85e4-19bc433c6cf7"
name: "test"
- uuid: "054e4e69-21b2-4662-aacd-2c7ee2d3dff2"
name: "test2"
Do you have a reproducer?
https://github.com/Jotschi/openapi-router-example-reproducer
Steps to reproduce
- Run
ContractTest
Hi @Jotschi ,
I wanted to debug your example, but this is really hard with a contract which is that big. Could you create a Contract which is as small as possible?
@pk-work I have reduced the contract as much as possible.
Hi,
the OpenAPI spec is wrong. examples must be a map [1], and not an array.
[1] https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object
I hope this solves your issue.