exegesis-js / exegesis

Tools for implementing server-side OpenAPI 3.0.0
MIT License
139 stars 36 forks source link

Feature request: Generating mocks responses #91

Open rodriguezc opened 5 years ago

rodriguezc commented 5 years ago

I implemented a controller that send mocks response using json-schema-faker v0.4.7. myController.js

const jsf = require('json-schema-faker');
jsf.option({ optionalsProbabilty: 0.5 });
const jsonSchema = require("exegesis/lib/utils/jsonSchema");
exports.getPartenaireById = function getPartenaireById(context) {
    const path = `${context.api.operationPtr}/responses/200/content/application~1json/schema`;
    let schema = jsonSchema.extractSchema(context.api.openApiDoc, path);
    const mock = jsf(schema);

    return mock;
}

Perhaps you have a good solution to make it generic and integrate it in the core or in a plugin?

Thanks

jwalton commented 5 years ago

Oh, very slick! It would be very cool to have this as a plugin.