swagger-node
swagger-node copied to clipboard
How does a mock controller work?
I have the following yaml snippet:
/test:
x-swagger-router-controller: test
get:
description: Testing
operationId: test
responses:
"200":
description: Success
default:
description: Error
Controller test.js in mock folder:
'use strict';
module.exports = {
test: test_function
};
function test_function(req, res) {
res.json('Hi, this is a test');
}
But it doesn't work. Can anybody tell how the mock controller works? Thanks.
It works if I put test.js inside controllers folder. But I want it inside mocks folder. Maybe my understanding is wrong about the mock controller. Then please tell me what the mocks folder is for?
That's exactly what the mocks folder is for. Are you running in mock mode? What are you seeing? Can you please run with DEBUG=swagger* environment var set?
You would probably need to run your api project with the -m
parameter, to run it in mock mode. See this.
old question but i'll reply
to run without mocking use ... swagger project start to run with mocking use ... swagger project start -m
when not mocking, swagger will use /api/controllers/[x-swagger-router-controller].js
when mocking, swagger will use:
/api/mocks/[x-swagger-router-controller].js if it exists, else it will fallback to using the response descriptions defined in swagger.yaml