@unleash/express-openapi
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -5,2 +5,3 @@ 'use strict' | ||
const { get: getSchema, set: setSchema } = require('./layer-schema') | ||
const extractPath = require('./extract-path') | ||
@@ -19,2 +20,5 @@ module.exports = function generateDocument (baseDocument, router) { | ||
iterateStack('', null, _layer, (path, routeLayer, layer) => { | ||
if (doc.servers && doc.servers.length === 1) { | ||
path = path.replace(extractPath(doc.servers[0].url), '') | ||
} | ||
const schema = getSchema(layer.handle) | ||
@@ -21,0 +25,0 @@ if (!schema || !layer.method) { |
{ | ||
"name": "@unleash/express-openapi", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Middleware for generating OpenAPI/Swagger documentation for your Express app", | ||
@@ -5,0 +5,0 @@ "author": "@unleash", |
@@ -418,2 +418,51 @@ 'use strict' | ||
test('support express nested sub-routes with base path', (done) => { | ||
const app = express() | ||
const router = express.Router() | ||
const subrouter = express.Router() | ||
const oapi = openapi({ servers: [ { url: '/sub-route' } ] }) | ||
const emptySchema = oapi.path({ | ||
responses: { | ||
204: { | ||
description: 'Successful response', | ||
content: { | ||
'application/json': {} | ||
} | ||
} | ||
} | ||
}) | ||
subrouter.get('/endpoint', emptySchema, (req, res) => { | ||
res.status(204).send() | ||
}) | ||
app.use(oapi) | ||
app.use('/sub-route', router) | ||
router.use('/sub-sub-route', subrouter) | ||
supertest(app) | ||
.get(`${openapi.defaultRoutePrefix}.json`) | ||
.expect(200, (err, res) => { | ||
assert(!err, err) | ||
SwaggerParser.validate(res.body, (err, api) => { | ||
if (err) { | ||
logDocument(api) | ||
done(err) | ||
} | ||
assert(api.paths['/sub-sub-route/endpoint']) | ||
assert(api.paths['/sub-sub-route/endpoint'].get) | ||
assert(api.paths['/sub-sub-route/endpoint'].get.responses[204]) | ||
assert.strictEqual( | ||
api.paths['/sub-sub-route/endpoint'].get.responses[204].description, | ||
'Successful response' | ||
) | ||
done() | ||
}) | ||
}) | ||
}) | ||
// Other tests | ||
@@ -420,0 +469,0 @@ require('./_validate')() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36819
17
1073
2