Skip to content

Commit

Permalink
fileUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Dec 30, 2019
1 parent 81243f8 commit 4749143
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ new OpenApiValidator({
.then(app => {
// 5. Define routes using Express
app.get('/v1/pets', function(req, res, next) {
res.json([{ id: 1, name: 'max' }, { id: 2, name: 'mini' }]);
res.json([
{ id: 1, name: 'max' },
{ id: 2, name: 'mini' },
]);
});

app.post('/v1/pets', function(req, res, next) {
Expand Down Expand Up @@ -364,7 +367,7 @@ new OpenApiValidator(options).install({
validateResponses: true,
ignorePaths: /.*\/pets$/
unknownFormats: ['phone-number', 'uuid'],
multerOpts: { ... },
fileUploader: { ... },
securityHandlers: {
ApiKeyAuth: (req, scopes, schema) => {
throw { status: 401, message: 'sorry' }
Expand Down Expand Up @@ -461,10 +464,22 @@ Defines how the validator should behave if an unknown or custom format is encoun

- `"ignore"` - to log warning during schema compilation and always pass validation. This option is not recommended, as it allows to mistype format name and it won't be validated without any error message.

### ▪️ multerOpts (optional)
### ▪️ fileUploader (optional)

Specifies the options to passthrough to multer. express-openapi-validator uses multer to handle file uploads. see [multer opts](https://github.com/expressjs/multer)

- `true` (**default**) - enables multer and provides simple file(s) upload capabilities
- `false` - disables file upload capability. Upload capabilities may be provided by the user
- `{...}` - multer options to be passed-through to multer. see [multer opts](https://github.com/expressjs/multer) for possible options

e.g.

```javascript
fileUploader: {
dest: 'uploads/';
}
```

### ▪️ coerceTypes (optional)

Determines whether the validator should coerce value types to match the type defined in the OpenAPI spec.
Expand Down
4 changes: 2 additions & 2 deletions test/multipart.disabled.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe(packageJson.name, () => {
.send('form_p1=stuff&form_p2=morestuff')
.expect(200));

// TODO make this work when fileUpload i.e. multer is disabled
it.skip('should return 200 for multipart/form-data with p1 and p2 fields present (with fileUpload false)', async () =>
// TODO make this work when fileUploader i.e. multer is disabled
it.skip('should return 200 for multipart/form-data with p1 and p2 fields present (with fileUploader false)', async () =>
request(app)
.post(`${app.basePath}/sample_1`)
.set('Content-Type', 'multipart/form-data')
Expand Down

0 comments on commit 4749143

Please sign in to comment.