outofcoffee / imposter

Scriptable, multipurpose mock server. Run standalone mock servers, or embed mocks within your tests.
https://imposter.sh
Other
364 stars 59 forks source link

Unable to get REST plug in #604

Closed GerardoGuzmanTR closed 2 months ago

GerardoGuzmanTR commented 2 months ago

After creating a simple rest mock:

plugin: rest
resource:
 - path: "/my-api"
   method: POST
   response:
     status: 200
     staticFile: response.json

Using a single self-containted Docker image:

FROM outofcoffee/imposter
COPY ./src/config/* /opt/imposter/config/
COPY ./src/templates/* /opt/imposter/config/

After building and running the image getting the next error:

15:57:55 INFO  i.g.i.Imposter - Starting mock engine 4.0.2
15:57:55 DEBUG i.g.i.c.u.ConfigUtil - Loading configuration file: /opt/imposter/config/config.yaml
15:57:57 DEBUG i.g.i.p.PluginManager - Loaded 7 plugin(s): [js-detector, store-detector, openapi, rest, soap, js-graal, store-inmem]
15:57:58 ERROR i.v.c.i.l.c.VertxIsolatedDeployer - Failed in deploying verticle
java.lang.RuntimeException: Error configuring plugin: rest
        at io.gatehill.imposter.plugin.PluginManagerImpl.configurePlugins(PluginManagerImpl.kt:133) ~[imposter-config-4.0.2.jar:?]
        at io.gatehill.imposter.plugin.PluginManagerImpl.startPlugins(PluginManagerImpl.kt:91) ~[imposter-config-4.0.2.jar:?]
        at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:132) ~[imposter-engine-4.0.2.jar:?]
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.10.jar:1.9.10-release-459]
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) ~[kotlinx-coroutines-core-jvm-1.7.3.jar:?]
Caused by: java.lang.RuntimeException: Error loading plugin config: LoadedConfig(ref=ConfigReference(file=/opt/imposter/config/config.yaml, configRoot=/opt/imposter/config), serialised=plugin: rest

[...]

  , plugin=rest)
        at io.gatehill.imposter.plugin.config.ConfiguredPlugin.loadConfiguration(ConfiguredPlugin.kt:79) ~[imposter-engine-4.0.2.jar:?]
        at io.gatehill.imposter.plugin.PluginManagerImpl.configurePlugins(PluginManagerImpl.kt:130) ~[imposter-config-4.0.2.jar:?]
        ... 8 more
Caused by: java.lang.RuntimeException: Error loading configuration file: /opt/imposter/config/config.yaml, reason: Unrecognized field "status" (class io.gatehill.imposter.plugin.config.resource.ResponseConfig), not marked as ignorable (9 known properties: "delay", "headers", "scriptFile", "content", "template", "file", "dir", "fail", "statusCode"])
 at [Source: (StringReader); line: 9, column: 18] (through reference chain: io.gatehill.imposter.plugin.rest.config.RestPluginConfig["resources"]->java.util.ArrayList[0]->io.gatehill.imposter.plugin.rest.config.RestPluginResourceConfig["response"]->io.gatehill.imposter.plugin.config.resource.ResponseConfig["status"])
        at io.gatehill.imposter.config.util.ConfigUtil.loadPluginConfig(ConfigUtil.kt:337) ~[imposter-config-4.0.2.jar:?]
        at io.gatehill.imposter.plugin.config.ConfiguredPlugin.loadConfiguration(ConfiguredPlugin.kt:74) ~[imposter-engine-4.0.2.jar:?]
        at io.gatehill.imposter.plugin.PluginManagerImpl.configurePlugins(PluginManagerImpl.kt:130) ~[imposter-config-4.0.2.jar:?]
        ... 8 more

To confirm that getting the plugin was the issue, use the imposter cli to try to get it:

$ imposter plugin install -d rest
time="2024-07-29T10:09:53-06:00" level=debug msg="plugin rest version 4.0.2 is not installed"
time="2024-07-29T10:09:53-06:00" level=debug msg="downloading https://github.com/outofcoffee/imposter/releases/download/v4.0.2/imposter-plugin-rest.jar"
time="2024-07-29T10:09:53-06:00" level=fatal msg="error ensuring plugin rest: error downloading from: : status code: 404"

After trying to directly get the jar from browser using the expected URL: https://github.com/outofcoffee/imposter/releases/download/v4.0.2/imposter-plugin-rest.jar

image

outofcoffee commented 2 months ago

Hi @GerardoGuzmanTR, thanks for raising this.

The issue here is:

Error loading configuration file: /opt/imposter/config/config.yaml,
reason: Unrecognized field "status" 
…
(9 known properties: "delay", "headers", "scriptFile", "content", "template", "file", "dir", "fail", "statusCode"])
at [Source: (StringReader); line: 9, column: 18]

This is caused by the use of status rather than statusCode in the configuration file.

GerardoGuzmanTR commented 2 months ago

You are right, it was actually an indentation and unrecognized field issue. Thanks!