Comments (4)
Hi @sjabiulla, thanks for your question. Imposter allows you to control the response behaviour via scripting, but this is limited to:
- the script determining which status code (and thus corresponding example) to return
- the script returning a literal string response
In other words, the examples themselves are not exposed to the scripts.
With option 2 you do have a way to fully control the response to your caller, but bear in mind the response wouldn't necessarily mirror the content in the spec file - it would be whatever string you configured in the script.
Here's some information about scripting responses: https://github.com/outofcoffee/imposter/blob/master/docs/scripting.md
from imposter.
Thanks for the detailed information.
But, can I script responses with openapi plugin?
I see that, in the example that's mentioned here https://github.com/outofcoffee/imposter/blob/master/docs/scripting.md is using REST plugin.
from imposter.
All current plugins support scripting.
If you were to take the example from above and change the plugin to openapi
, and remove the path
portion you don't need, it would look like this:
# scripted-openapi-config.yaml
---
plugin: openapi
specFile: petstore.yaml
response:
scriptFile: example.groovy
This way your example.groovy
can control the responses, including specifying:
- a specific example name to return
respond().withExampleName('example1')
- the content of a file to return
respond().withFile('some-file.json')
- a literal string to return
respond().withContent('{ "foo": "bar" }')
from imposter.
Documentation updated: https://github.com/outofcoffee/imposter/blob/master/docs/openapi_plugin.md
from imposter.
Related Issues (20)
- Using Expression.regexify in content responses HOT 2
- Request to make Context.Request.toString() produce json HOT 1
- Add support for faker regexify and similar functions
- Let a percentage of requests fail HOT 2
- CLI tool doesn't download and extract zip files for plugins HOT 1
- [Question] Find SOAP operations HOT 1
- Use of `delay` in AWS Lambda results in empty response HOT 3
- Question - SOAP - Error on "No operations found matching body root" HOT 5
- Upgrade base image to newer version to resolve vunerabilities HOT 3
- [Question] How can I serve WSDL file with SOAP plugin ? HOT 2
- NPE while parsing a WSDL with rpc/encoded style HOT 2
- Precompiling js script files fails from docker container HOT 6
- SOAP : WSDL with includes fails parsing HOT 1
- Autoreload when using docker and config files change HOT 2
- Support for RPC style SOAP services HOT 2
- Support XML attributes in SOAP request body XPath
- Unable to format data from store as JSON in javascript script handler HOT 8
- SQS plugin
- Scheduled steps
- SOAP: WSDL with targetNamespace and messages without namespace prefix parsing issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imposter.