Skip to content
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

Openapi RouterBuilder as subrouter does not correctly parse path parameters #2694

Open
rzorzorzo opened this issue Dec 31, 2024 · 1 comment
Labels

Comments

@rzorzorzo
Copy link

Version

5.0.0.CR3

Context

The openapi router with GET /data/{id} is added as a subrouter to /api/test

Invoking http://localhost:8082/api/test/data/1 throws a validation exception:

The value of path parameter id is invalid. Reason: Instance type string is invalid. Expected integer

Debugging RequestValidatorImpl.validate shows that in request.path key "id" has value "test"

however, if the parameter type constraint is removed, invoking RoutingContext.pathParams() in the route handler returns the expected value: id -> 1

Do you have a reproducer?

verticle:

HttpServer server = vertx.createHttpServer();
Router global = Router.router(vertx);
OpenAPIContract.from(vertx, "openapi.json").onSuccess(contract -> {
RouterBuilderImpl routerBuilder = (RouterBuilderImpl) RouterBuilder.create(vertx, contract);
for (Operation op : contract.operations()) {
String opid = op.getOperationId();
String address = "api.test." + opid;
DeliveryOptions dOptions = new DeliveryOptions().setLocalOnly(true);
routerBuilder.getRoute(opid)
.addHandler(RouteToEBServiceHandler.build(vertx.eventBus(), address, address, dOptions));
}
Router subrouter = routerBuilder.createRouter();
Route route = global.route("/api/test/*").subRouter(subrouter);
server.requestHandler(global).listen(8082);}).onFailure((e) -> e.printStackTrace());

openapi:

"/data/{id}": {
"get": {
"responses": {
"200": {
"content": {
"application/json": {}
},
"description": "ok"
}
},
"operationId": "getData"
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
}
]
}

@rzorzorzo rzorzorzo added the bug label Dec 31, 2024
@rzorzorzo
Copy link
Author

PS:
the problem is in RequestUtils.extract
calculating the segment from the end of the url instead of the begining solves the issue:

//return new RequestParameterImpl(decodeUrl(pathSegments[segment - 1]));
return new RequestParameterImpl(decodeUrl(pathSegments[pathSegments.length - segment-1]));

//return (int) templatePath.subSequence(0, idx).chars().filter(c -> c == '/').count();
return (int)
(templatePath.chars().filter(c -> c == '/').count() -
templatePath.subSequence(0, idx).chars().filter(c -> c == '/').count());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant