Giter Club home page Giter Club logo

Comments (4)

outofcoffee avatar outofcoffee commented on May 26, 2024

Hi @sjabiulla, thanks for your question. Imposter allows you to control the response behaviour via scripting, but this is limited to:

  1. the script determining which status code (and thus corresponding example) to return
  2. 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.

sjabiulla avatar sjabiulla commented on May 26, 2024

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.

outofcoffee avatar outofcoffee commented on May 26, 2024

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:

  1. a specific example name to return
respond().withExampleName('example1')
  1. the content of a file to return
respond().withFile('some-file.json')
  1. a literal string to return
respond().withContent('{ "foo": "bar" }')

from imposter.

outofcoffee avatar outofcoffee commented on May 26, 2024

Documentation updated: https://github.com/outofcoffee/imposter/blob/master/docs/openapi_plugin.md

from imposter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.