Comments (2)
You're not the first person to ask about this. It should definitely be possible.
We have infrastructure for plugins already which should have most of what you'd need to do this. Off the top of my head, if I was going to do this, I'd traverse all the paths
in the apidoc
at the top level of makeExegesisPlugin()
(because this is where you're allowed to modify the apidoc) and replace all the x-exegesis-controller
s with something like mockController
, and for each one I'd add a new method to my mockController
object which just returns whatever the first defined response is for that path.
The first tricky bit is constructing a valid response; if there's an example
at the top level of the schema object, you can just steal that, but if there isn't you'd have to use something like json-schema-traverse to walk the schema and construct a valid example as you go. swagger-ui
does something similar to generate examples, so you might be able to steal some code from them, but it might be faster to just rewrite this from scratch (maybe make it a package in it's own right... Or, now that I say that, maybe there's already a package out there that does something like this!)
The second tricky bit is, I'm not sure where you'd get a chance to insert the mockController
. Again, off the top of my head, I'd suggest makeExegesisPlugin()
should be passed an { apiDoc, options }
object, with the raw objects that were passed into Exegesis, and then you could add your options there. The idea would be to let plugins modify the options
object before it gets passed to compileOptions
, because that does a bunch of sanity checking, adds default options, sanitizes the passed in bodyParsers, etc... and I don't think we'd want plugins to be mucking about with options after we do all of that. Might need a tiny bit of refactoring to make sure all the plugins get build prior to the call to compileOptions()
, but that shouldn't be too bad.
I wouldn't mind taking a stab at something like this, but I can tell you we're a little short staffed at work right now, and I'm pretending to be DevOps and learning Kubernetes, so it might be a little while before I get a chance. But if you think that's enough to get you started, feel free to give it a go - I'm happy to answer any questions if you get stuck. :)
from exegesis.
json-schema-faker might be a good place to start for generating responses, although I bet it ignores the example
keyword, because I'm pretty sure that's OAS3 specific.
from exegesis.
Related Issues (20)
- Can not demand an array to be one or more items long HOT 2
- Crash with recursive definition in referenced OpenAPI file HOT 5
- Incorrectly failing validation under a weird condition HOT 4
- Validation error of request body when oneOf is used HOT 5
- Crash with recursive definition in referenced OpenAPI file is back again
- Does not work well with newest json-ptr (1.3.1) HOT 2
- Your .dependabot/config.yml contained invalid details HOT 1
- Export class from controller HOT 2
- Could not find controller if controller is a .ts file HOT 2
- Can we access "ExegesisContext" at express middleware(app.use) not controllers/*.ts HOT 1
- How to filter the request body by only passing the defined requestBody schema? HOT 2
- Security vulnerability in `json-ptr` HOT 4
- Exegesis 3.0.0 using updated ajv outputs issues with OpenAPI spec, but 2.0.0 did not HOT 5
- res.redirect not supported HOT 3
- Is OpenAPI 3.1 supported?
- Bump json-ptr to fix security vulnerability HOT 1
- Support for additional string formats HOT 2
- json-schema-ref-parser dependency breaks node engine < 17 HOT 3
- How to use exegesis with multipart/form-data?
- Mime-types HOT 2
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 exegesis.