-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* hf: fixes #778 restores behavior of binding the operation, or (new behavior) by binding each middleware in the array * handle node16 error message * fix linting (why isnt prettier a precommit hook?) * adds test with same controller supporting multiple operations in express * fix linting
- Loading branch information
Showing
7 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...pi/test/sample-projects/with-multiple-operations-sharing-the-same-controller/api-doc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "sample api doc", | ||
"version": "3" | ||
}, | ||
"paths": { | ||
"/foo": { | ||
"get": { | ||
"operationId": "getFoo", | ||
"responses": { | ||
"default": { | ||
"description": "return foo", | ||
"schema": {} | ||
} | ||
} | ||
} | ||
}, | ||
"/foo-two": { | ||
"get": { | ||
"operationId": "getFooTwo", | ||
"responses": { | ||
"default": { | ||
"description": "same controller mounted on another path with different operationId", | ||
"schema": {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...-openapi/test/sample-projects/with-multiple-operations-sharing-the-same-controller/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var app = require('express')(); | ||
var bodyParser = require('body-parser'); | ||
// normally you'd just do require('express-openapi'), but this is for test purposes. | ||
var openapi = require('../../../'); | ||
var path = require('path'); | ||
var cors = require('cors'); | ||
|
||
app.use(cors()); | ||
app.use(bodyParser.json()); | ||
|
||
//shared controller | ||
function controller(req, res, next) { | ||
return res.json(req.operationDoc); | ||
} | ||
|
||
openapi.initialize({ | ||
apiDoc: require('./api-doc.json'), | ||
app: app, | ||
promiseMode: true, | ||
operations: { | ||
getFoo: controller, | ||
getFooTwo: controller, | ||
}, | ||
}); | ||
|
||
app.use(function (err, req, res, next) { | ||
res.status(err.status).json(err.message); | ||
}); | ||
|
||
module.exports = app; | ||
|
||
var port = parseInt(process.argv[2], 10); | ||
if (port) { | ||
app.listen(port); | ||
} |
45 changes: 45 additions & 0 deletions
45
...openapi/test/sample-projects/with-multiple-operations-sharing-the-same-controller/spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const expect = require('chai').expect; | ||
const request = require('supertest'); | ||
let app; | ||
|
||
before(function () { | ||
app = require('./app.js'); | ||
}); | ||
|
||
it('should return the correct operationDoc for getFoo', () => { | ||
const expectedDoc = { | ||
operationId: 'getFoo', | ||
responses: { | ||
default: { | ||
description: 'return foo', | ||
schema: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
request(app) | ||
.get('/foo') | ||
.expect(200) | ||
.end(function (err, res) { | ||
expect(res.body).to.eql(expectedDoc); | ||
}); | ||
}); | ||
|
||
it('should return the correct operation doc for getFooTwo', () => { | ||
const expectedDoc = { | ||
operationId: 'getFooTwo', | ||
responses: { | ||
default: { | ||
description: | ||
'same controller mounted on another path with different operationId', | ||
schema: {}, | ||
}, | ||
}, | ||
}; | ||
request(app) | ||
.get('/foo-two') | ||
.expect(200) | ||
.end(function (err, res) { | ||
expect(res.body).to.eql(expectedDoc); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters