loopbackio / loopbackio/loopback-next
Model type "buffer" is not working
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
### Describe the bug
Getting below error after creating model with **buffer** type property.
> Request POST /tests failed with status code 500. Error: type must be JSONType or JSONType[]: buffer
**Model Property** (Entity):
`@property({
type: 'buffer',
})
image?: Buffer;
`
Steps to reproduce:
1. Create new app: lb4 app
2. Add new model with buffer type property (not required field): lb4 model
3. Add any type of db: lb4 datasource
4. Create repository: lb4 repository
5. Create controller with all CRUD operations: lb4 controller
6. Test POST request on explorer
### Logs
```shell
Request POST /tests failed with status code 500. Error: type must be JSONType or JSONType[]: buffer
at getJSONTypes (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/dataType.ts:36:9)
at getSchemaTypes (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/dataType.ts:20:17)
at typeAndKeywords (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:159:31)
at subSchemaObjCode (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:147:3)
at subschemaCode (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:124:7)
at KeywordCxt.subschema (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:491:5)
at applyPropertySchema (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/vocabularies/applicator/properties.ts:45:11)
at Object.code (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/vocabularies/applicator/properties.ts:32:9)
at keywordCode (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:523:9)
at /Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:265:9
at CodeGen.code (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/codegen/index.ts:525:33)
at CodeGen.block (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/codegen/index.ts:680:20)
at iterateKeywords (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:262:7)
at groupKeywords (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:241:7)
at /Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/validate/index.ts:233:38
at CodeGen.code (/Users/shailendrasingh/Documents/workspace/testapp/node_modules/ajv/lib/compile/codegen/index.ts:525:33)
```
### Additional information
_No response_
### Reproduction
https://github.com/shailendramonu/testlb4app
Contributor guide
Research direction
Open the linked reproduction and recreate the generated model, datasource, repository, controller, and POST request described in the issue. Trace the validation path that rejects the model's optional Buffer property, then add coverage showing that the POST request no longer fails with the AJV JSONType error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100