Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/express-openapi/test/sample-projects/with-request-validation-ajvOptions/api-doc.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,39 @@ | ||
// args.apiDoc needs to be a js object. This file could be a json file, but we can't add | ||
// comments in json files. | ||
module.exports = { | ||
swagger: '2.0', | ||
|
||
// all routes will now have /v3 prefixed. | ||
basePath: '/v3', | ||
|
||
info: { | ||
title: 'express-openapi sample project', | ||
version: '3.0.0', | ||
}, | ||
|
||
definitions: { | ||
Error: { | ||
additionalProperties: true, | ||
}, | ||
User: { | ||
properties: { | ||
name: { | ||
type: 'string', | ||
}, | ||
friends: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
}, | ||
required: ['name'], | ||
additionalProperties: false, | ||
}, | ||
}, | ||
|
||
// paths are derived from args.routes. These are filled in by fs-routes. | ||
paths: {}, | ||
|
||
tags: [{ name: 'users' }], | ||
}; |
54 changes: 54 additions & 0 deletions
54
...-openapi/test/sample-projects/with-request-validation-ajvOptions/api-routes/users/{id}.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,54 @@ | ||
module.exports = { | ||
// parameters for all operations in this path | ||
parameters: [ | ||
{ | ||
name: 'id', | ||
in: 'path', | ||
type: 'string', | ||
required: true, | ||
description: "Fred's age.", | ||
}, | ||
], | ||
// or they may also be an array of middleware + the method handler. This allows | ||
// for flexible middleware management. express-openapi middleware generated from | ||
// the <path>.parameters + <methodHandler>.apiDoc.parameters is prepended to this | ||
// array. | ||
post: [ | ||
function (req, res, next) { | ||
next(); | ||
}, | ||
function (req, res) { | ||
res.status(200).json(req.body); | ||
}, | ||
], | ||
}; | ||
|
||
module.exports.post.apiDoc = { | ||
description: 'Create a user.', | ||
operationId: 'createUser', | ||
tags: ['users'], | ||
parameters: [ | ||
{ | ||
name: 'user', | ||
in: 'body', | ||
schema: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
], | ||
|
||
responses: { | ||
200: { | ||
description: 'Requested user', | ||
schema: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
default: { | ||
description: 'Unexpected error', | ||
schema: { | ||
$ref: '#/definitions/Error', | ||
}, | ||
}, | ||
}, | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/express-openapi/test/sample-projects/with-request-validation-ajvOptions/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,28 @@ | ||
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()); | ||
|
||
openapi.initialize({ | ||
apiDoc: require('./api-doc.js'), | ||
app: app, | ||
paths: path.resolve(__dirname, 'api-routes'), | ||
requestAjvOptions: { removeAdditional: true }, | ||
}); | ||
|
||
app.use(function (err, req, res, next) { | ||
err.status = err.status || 500; | ||
res.status(err.status).json(err); | ||
}); | ||
|
||
module.exports = app; | ||
|
||
var port = parseInt(process.argv[2], 10); | ||
if (port) { | ||
app.listen(port); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/express-openapi/test/sample-projects/with-response-validation-ajvOptions/api-doc.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,53 @@ | ||
// args.apiDoc needs to be a js object. This file could be a json file, but we can't add | ||
// comments in json files. | ||
module.exports = { | ||
swagger: '2.0', | ||
|
||
// all routes will now have /v3 prefixed. | ||
basePath: '/v3', | ||
|
||
info: { | ||
title: 'express-openapi sample project', | ||
version: '3.0.0', | ||
}, | ||
|
||
definitions: { | ||
Error: { | ||
additionalProperties: true, | ||
}, | ||
User: { | ||
properties: { | ||
name: { | ||
type: 'string', | ||
}, | ||
friends: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
}, | ||
required: ['name'], | ||
}, | ||
UserRes: { | ||
properties: { | ||
name: { | ||
type: 'string', | ||
}, | ||
friends: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
}, | ||
required: ['name'], | ||
additionalProperties: false, | ||
}, | ||
}, | ||
|
||
// paths are derived from args.routes. These are filled in by fs-routes. | ||
paths: {}, | ||
|
||
tags: [{ name: 'users' }], | ||
}; |
55 changes: 55 additions & 0 deletions
55
...openapi/test/sample-projects/with-response-validation-ajvOptions/api-routes/users/{id}.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,55 @@ | ||
module.exports = { | ||
// parameters for all operations in this path | ||
parameters: [ | ||
{ | ||
name: 'id', | ||
in: 'path', | ||
type: 'string', | ||
required: true, | ||
description: "Fred's age.", | ||
}, | ||
], | ||
// or they may also be an array of middleware + the method handler. This allows | ||
// for flexible middleware management. express-openapi middleware generated from | ||
// the <path>.parameters + <methodHandler>.apiDoc.parameters is prepended to this | ||
// array. | ||
post: [ | ||
function (req, res, next) { | ||
next(); | ||
}, | ||
function (req, res) { | ||
res.validateResponse(200, req.body); | ||
res.status(200).json(req.body); | ||
}, | ||
], | ||
}; | ||
|
||
module.exports.post.apiDoc = { | ||
description: 'Create a user.', | ||
operationId: 'createUser', | ||
tags: ['users'], | ||
parameters: [ | ||
{ | ||
name: 'user', | ||
in: 'body', | ||
schema: { | ||
$ref: '#/definitions/User', | ||
}, | ||
}, | ||
], | ||
|
||
responses: { | ||
200: { | ||
description: 'Requested user', | ||
schema: { | ||
$ref: '#/definitions/UserRes', | ||
}, | ||
}, | ||
default: { | ||
description: 'Unexpected error', | ||
schema: { | ||
$ref: '#/definitions/Error', | ||
}, | ||
}, | ||
}, | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/express-openapi/test/sample-projects/with-response-validation-ajvOptions/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,28 @@ | ||
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()); | ||
|
||
openapi.initialize({ | ||
apiDoc: require('./api-doc.js'), | ||
app: app, | ||
paths: path.resolve(__dirname, 'api-routes'), | ||
responseAjvOptions: { removeAdditional: true }, | ||
}); | ||
|
||
app.use(function (err, req, res, next) { | ||
err.status = err.status || 500; | ||
res.status(err.status).json(err); | ||
}); | ||
|
||
module.exports = app; | ||
|
||
var port = parseInt(process.argv[2], 10); | ||
if (port) { | ||
app.listen(port); | ||
} |
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
7 changes: 7 additions & 0 deletions
7
packages/openapi-framework/test/sample-projects/with-requestAjvOptions/apiDoc.yml
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,7 @@ | ||
swagger: '2.0' | ||
info: | ||
title: sample api doc | ||
version: '3' | ||
security: | ||
- basic: [] | ||
paths: {} |
23 changes: 23 additions & 0 deletions
23
packages/openapi-framework/test/sample-projects/with-requestAjvOptions/paths/foo.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,23 @@ | ||
module.exports = { | ||
GET, | ||
}; | ||
|
||
function GET() { | ||
return; | ||
} | ||
GET.apiDoc = { | ||
parameters: [ | ||
{ | ||
format: 'foo', | ||
in: 'query', | ||
name: 'foo', | ||
type: 'string', | ||
}, | ||
], | ||
responses: { | ||
default: { | ||
description: 'return foo', | ||
schema: {}, | ||
}, | ||
}, | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/openapi-framework/test/sample-projects/with-requestAjvOptions/spec.ts
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,21 @@ | ||
import { expect } from 'chai'; | ||
import OpenapiFramework from '../../../'; | ||
const path = require('path'); | ||
|
||
describe(path.basename(__dirname), () => { | ||
let framework: OpenapiFramework; | ||
|
||
beforeEach(() => { | ||
framework = new OpenapiFramework({ | ||
apiDoc: path.resolve(__dirname, 'apiDoc.yml'), | ||
featureType: 'middleware', | ||
name: 'some-framework', | ||
paths: path.resolve(__dirname, 'paths'), | ||
requestAjvOptions: { removeAdditional: true }, | ||
}); | ||
}); | ||
|
||
it('should work', () => { | ||
framework.initialize({}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/openapi-framework/test/sample-projects/with-responseAjvOptions/apiDoc.yml
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,7 @@ | ||
swagger: '2.0' | ||
info: | ||
title: sample api doc | ||
version: '3' | ||
security: | ||
- basic: [] | ||
paths: {} |
23 changes: 23 additions & 0 deletions
23
packages/openapi-framework/test/sample-projects/with-responseAjvOptions/paths/foo.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,23 @@ | ||
module.exports = { | ||
GET, | ||
}; | ||
|
||
function GET() { | ||
return; | ||
} | ||
GET.apiDoc = { | ||
parameters: [ | ||
{ | ||
format: 'foo', | ||
in: 'query', | ||
name: 'foo', | ||
type: 'string', | ||
}, | ||
], | ||
responses: { | ||
default: { | ||
description: 'return foo', | ||
schema: {}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.