Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fixes #33 discovery mode
Browse files Browse the repository at this point in the history
  • Loading branch information
brevity committed Mar 21, 2018
1 parent 7a490e5 commit 5b9c784
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions bin/osprey-mock-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ var morgan = require('morgan')
var argv = require('yargs')
.usage(
'Generate an API mock server from a RAML definition.\n\n' +
'Usage: $0 -f [file] -p [port number] --cors'
'Usage: $0 -f [file] -p [port number] --cors --definition [definition uri]'
)
.demand(['f', 'p'])
.describe('f', 'Path to the RAML definition')
.describe('p', 'Port number to bind the proxy')
.describe('cors', 'Enable CORS with the API')
.describe('definition', 'URI of raml definition')
.argv

var options = {
cors: !!argv.cors
cors: !!argv.cors,
definition: argv.definition || false
}

mock.loadFile(argv.f, options)
Expand Down
8 changes: 8 additions & 0 deletions osprey-mock-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ function createServerFromBaseUri (raml, options) {
var app = osprey.Router()
var path = (raml.baseUri || '').replace(/^(\w+:)?\/\/[^/]+/, '') || '/'

if (options.definition) {
app.use('/resources', function (req, res) {
var body = '< link:"' +
options.definition +
'" rel="describedby" type="application/raml+yaml">'
res.end(body)
})
}
app.use(path, raml.baseUriParameters, createServer(raml, options))

return app
Expand Down
17 changes: 16 additions & 1 deletion test/test10.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ describe('osprey mock service v1.0', function () {

beforeEach(function () {
this.timeout(3000)
return mockService.loadFile(path.join(__dirname, '/fixtures/example10.raml'), { server: { cors: true, compression: true } })
return mockService.loadFile(path.join(__dirname, '/fixtures/example10.raml'), {
server: { cors: true, compression: true }, definition: 'http://example.com/api.raml'
})
.then(function (raml) {
http = httpes.createServer(function (req, res) {
return raml(req, res, finalhandler(req, res))
Expand Down Expand Up @@ -147,5 +149,18 @@ describe('osprey mock service v1.0', function () {
expect(res.headers.foo).to.be.oneOf(['bar', 'foo', 'random', 'another'])
})
})

it('should return a link to the raml definition', function () {
return popsicle.default(
{
method: 'GET',
url: '/resources'
}
)
.use(server(http))
.then(function (res) {
expect(res.body).to.equal('< link:"http://example.com/api.raml" rel="describedby" type="application/raml+yaml">')
})
})
})
})

0 comments on commit 5b9c784

Please sign in to comment.