Skip to content

Commit 38a7a39

Browse files
committed
camalize errors if they are dasherized
1 parent 22bee89 commit 38a7a39

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/util/validation-errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSORMBase } from "../model"
2-
import { camelize } from "inflected"
2+
import { camelize, underscore } from "inflected"
33
import { JsonapiResponseDoc, JsonapiErrorMeta } from "../jsonapi-spec"
44

55
export class ValidationErrors {
@@ -44,7 +44,7 @@ export class ValidationErrors {
4444
let attribute = meta.attribute
4545

4646
if (this.model.klass.camelizeKeys) {
47-
attribute = camelize(attribute, false)
47+
attribute = camelize(underscore(attribute), false)
4848
}
4949

5050
errorsAccumulator[attribute] = meta.message

test/integration/validations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const resetMocks = () => {
2323
status: "422",
2424
title: "Validation Error",
2525
detail: "Last Name cannot be blank",
26-
meta: { attribute: "last_name", message: "cannot be blank" }
26+
meta: { attribute: "last-name", message: "cannot be blank" }
2727
},
2828
{
2929
code: "unprocessable_entity",
@@ -136,7 +136,7 @@ describe("validations", () => {
136136

137137
expect(instance.errors).to.deep.equal({
138138
first_name: "cannot be blank",
139-
last_name: "cannot be blank"
139+
"last-name": "cannot be blank"
140140
})
141141
})
142142
})

0 commit comments

Comments
 (0)