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

fixes #33 discovery mode #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't required an extra parameter here. Instead, we should build the URL based on the API baseUri of the RAML file provided by -f.

.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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why /resources? the way I read #33 is that it should work with all resources defined in the RAML definition.

var body = '< link:"' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the < is extraneous. It appears in the example of #33 because that's how curl formats headers returned in responses.

Also, to be clear, this should be returned as a header, not in the body.

options.definition +
'" rel="describedby" type="application/raml+yaml">'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The > here is wrong too. This should follow the header Link syntax as defined here.

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">')
})
})
})
})