Open emanual4real opened 3 years ago
My fault, been playing with a couple variations. If I modify the controller to requestBody.array()
I get the 415 error instead of 422.
@requestBody.array({
description: 'User model instance',
content: {
'application/json-patch+json': {
schema: {
type: 'array',
items: getModelSchemaRef(JsonPatch),
},
},
required: true,
},
})
stack error
[2021-07-14T14:09:44.102Z] ERROR (UserService/21200 on CHRDEV42725):
requestId: "RequestContext-57g6pfjtTD_EV-UkMD2NZQ-6"
correlationId: "57g6pfjtTD_EV-UkMD2NZQ-7"
event: "rest.sequence.actions.reject"
err: {
"type": "UnsupportedMediaTypeError",
"message": "Content-type application/json-patch+json does not match [application/json].",
"stack":
UnsupportedMediaTypeError: Content-type application/json-patch+json does not match [application/json].
at Object.unsupportedMediaType (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\rest-http-error.ts:32:26)
at RequestBodyParser._matchRequestBodySpec (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\body-parsers\body-parser.ts:129:28)
at RequestBodyParser.loadRequestBodyIfNeeded (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\body-parsers\body-parser.ts:54:52)
at Object.parseOperationArgs (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\parser.ts:44:40)
at D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\providers\parse-params.provider.ts:68:28
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\express\src\middleware-interceptor.ts:131:19
at D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\express\src\middleware-interceptor.ts:131:19
at D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\providers\send.provider.ts:46:24
at MySequence.handle (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\sequence.ts:291:5)
at HttpHandler._handleRequest (D:\Workspace\javascript\opsdash-services-test\opsdash-services\packages\user-service\node_modules\@loopback\rest\src\http-handler.ts:115:5)
"code": "UNSUPPORTED_MEDIA_TYPE",
"contentType": "application/json-patch+json",
"allowedMediaTypes": [
"application/json"
],
"status": 415,
"statusCode": 415,
"expose": true
}
[2021-07-14T14:09:44.136Z] INFO (UserService/21200 on CHRDEV42725):
requestId: "RequestContext-57g6pfjtTD_EV-UkMD2NZQ-6"
correlationId: "57g6pfjtTD_EV-UkMD2NZQ-7"
user: {
"id": "00u14kjbo3IK5P8Fp5d7",
"groups": []
}
req: {
"method": "PATCH",
"url": "/users/me",
"query": {},
"params": {},
"headers": {
"host": "localhost:8080",
"connection": "keep-alive",
"content-length": "126",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"",
"authorization": "[Redacted]",
"sec-ch-ua-mobile": "?0",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
"content-type": "application/json-patch+json",
"accept": "*/*",
"origin": "http://localhost:3001",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "http://localhost:3001/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"x-correlation-id": "57g6pfjtTD_EV-UkMD2NZQ-7"
},
"remoteAddress": "::1",
"remotePort": 59861
}
res: {
"statusCode": 415,
"headers": {
"x-powered-by": "Express",
"x-correlation-id": "57g6pfjtTD_EV-UkMD2NZQ-7",
"access-control-allow-origin": "*",
"access-control-allow-credentials": "true",
"content-type": "application/problem+json; charset=utf-8",
"content-length": "152",
"etag": "W/\"98-MRnxNanuvSuM0nDMJLXs3JKTDdI\""
}
}
duration: 39.035
event: "access"
Steps to reproduce
Current Behavior
UnsupportedMediaTypeError: Content-type application/json-patch+json does not match [application/json]
Expected Behavior
I expect the application to accept
application/json-patch+json
media typeLink to reproduction sandbox
Work won't allow me to put code in sandbox.
Additional information
win32 x64 14.16.0 +-- @loopback/authentication@7.3.1 +-- @loopback/authentication-passport@3.2.1 +-- @loopback/boot@3.4.1 +-- @loopback/core@2.16.1 +-- @loopback/repository@3.7.0 +-- @loopback/rest@9.3.1 +-- @loopback/rest-explorer@3.3.1 +-- @loopback/security@0.5.1 +-- @loopback/service-proxy@3.2.1 +-- UNMET DEPENDENCY @opsdash/loopback-okta-auth@^0.0.1npm +-- @raad/loopback-logging@2.0.1 +-- @raad/loopback-problems@1.0.1ERR! peer dep missing: eslint-plugin-spellcheck@^0.0.17, required by @raad/eslint-config-codestyle-typescript@5.0.5 npm+-- loopback-connector-mongodb@6.0.1 ERR! missing: @opsdash/loopback-okta-auth@^0.0.1, required by @opsdash/user-service@0.0.1
specific controller
JsonPatch model
error stack
Request body