outofcoffee / imposter

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

Access to OpenAPI 'operation' object in es2022 scripting. #621

Open cooperaj opened 2 months ago

cooperaj commented 2 months ago

I'm trying to do some slightly more complex mocking by using the '@imposter-js/types' library in a built index.js file but am finding that I don't have access to the context.operation object under the Graal interpreter.

Trying to log it out gives me 14:06:34 INFO s./opt/imposter/config/mock-responses - Operation function () { [native code] } - where 'Operation' is a string prefix on the log line. This tells me it's there but it does not behave as I'd expect as trying to use context.operation.operationId does not work.

It looks like the '@imposter-js/types' library does not natively export the context here annoyingly but in this case I think that just results in a lack of autocomplete when editing.

EDIT I've just discovered that I can instead use the getOperationId() method (after editing my custom types) and this works.

outofcoffee commented 1 week ago

Thanks @cooperaj.

We might look at using the js.foreign-object-prototype setting in Graal to see if this can autogenerate the operationId property.