outofcoffee/imposter

[Bug] Path parameters with colon throws Vertx error

vglaeser opened this issue · 3 comments

Hey,

I am using imposter for testing-purposes with an openapi.json which is generated by an FastAPI-application.
Unfortunately, I cannot get imposter to work when I use path parameters with a colon, such as "/observers/uuid:{observer_uuid}".
It seems that Vert.x does not handle the path parameters correctly (or I am defining them wrong), because it fails with the following message

ERROR i.v.c.i.l.c.VertxIsolatedDeployer - Failed in deploying verticle
2024-06-19T21:48:38.996390671Z java.lang.IllegalArgumentException: path param does not follow the variable naming rules, expected (2) found (1)
2024-06-19T21:48:38.996394424Z 	at io.vertx.ext.web.impl.RouteImpl.setPath(RouteImpl.java:308) ~[vertx-web-4.4.5.jar:4.4.5]
2024-06-19T21:48:38.996397138Z 	at io.vertx.ext.web.impl.RouteImpl.<init>(RouteImpl.java:57) ~[vertx-web-4.4.5.jar:4.4.5]
2024-06-19T21:48:38.996399719Z 	at io.vertx.ext.web.impl.RouterImpl.route(RouterImpl.java:80) ~[vertx-web-4.4.5.jar:4.4.5]
2024-06-19T21:48:38.996413279Z 	at io.gatehill.imposter.server.vertxweb.VertxWebServerFactoryImpl.convertRouterToVertx(VertxWebServerFactoryImpl.kt:145) ~[imposter-adapter-vertxweb-3.41.2.jar:?]
2024-06-19T21:48:38.996416057Z 	at io.gatehill.imposter.server.vertxweb.VertxWebServerFactoryImpl.provide(VertxWebServerFactoryImpl.kt:92) ~[imposter-adapter-vertxweb-3.41.2.jar:?]
2024-06-19T21:48:38.996418521Z 	at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:136) ~[imposter-engine-3.41.2.jar:?]
2024-06-19T21:48:38.996421080Z 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.10.jar:1.9.10-release-459]
2024-06-19T21:48:38.996424136Z 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
2024-06-19T21:48:38.996425987Z 	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
2024-06-19T21:48:38.996427595Z 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
2024-06-19T21:48:38.996429201Z 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
2024-06-19T21:48:38.996430868Z 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]

I am using the following configuration:
docker-compose:

version: "3.0"

services:
  openapi_mock_imposter_test:
    container_name: openapi_mock_imposter_test
    image: outofcoffee/imposter-openapi
    environment:
      - IMPOSTER_CONFIG_SCAN_RECURSIVE=true
    volumes:
      - ./imposter-config_test:/opt/imposter/config
      - ./src/app/api/openapi_test.json:/opt/imposter/openapi-config/openapi.json
    ports:
      - "80:8080"

imposter-config (at ./imposter-config_test/test-mock-config.yml):

plugin: openapi
specFile: ../openapi-config/openapi.json
cors:
  allowOrigins: all

openapi_test.json

It seems that the error is thrown in Vert.X (RouteImpl.java). Here, the first counter params seems to overcount.

Is there any way to use imposter with such path parameters.

Best regards

Hi @vglaeser, thanks for raising this.

For the /observers/uuid:{observer_uuid} path, Imposter attempts to parse the colon in the path param as the start of a parameter name.

This is because Imposter supports a legacy format for path params in the Vert.x style, such as /somepath/:paramName

Hi @vglaeser, there's a new option: IMPOSTER_ESCAPE_COLONS_IN_PATH, which should work-around this issue.

It's released in v3.42.0. Please let us know if this solves the issue.

That seems to work.
Thank you for the quick fix!