Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Commit cb586f0

Browse files
committed
Constraint violations return a 422 Unprocessable Entity response instead of 400 Bad Request
1 parent c99de6f commit cb586f0

9 files changed

Lines changed: 11 additions & 26 deletions

File tree

http-tests/linked-data-templates/ct/GET-link-headers.sh

100644100755
File mode changed.

http-tests/linked-data-templates/custom/POST-shacl-constraint-400.sh renamed to http-tests/linked-data-templates/custom/POST-shacl-constraint-422.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
initialize_dataset "$BASE_URL_WRITABLE" "../../dataset.trig" "$ENDPOINT_URL_WRITABLE"
66

7-
# expect 400 Bad Request because missing <http://example.com/constrained-predicate> fails SHACLConstrainedType constraint validation
7+
# expect 422 Unprocessable Entity because missing <http://example.com/constrained-predicate> fails SHACLConstrainedType constraint validation
88

99
(
1010
curl -w "%{http_code}\n" -f -s \
@@ -15,4 +15,4 @@ curl -w "%{http_code}\n" -f -s \
1515
<${BASE_URL_WRITABLE}default-subject-post> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://github.com/AtomGraph/Processor/blob/develop/http-tests/custom#SHACLConstrainedType> .
1616
EOF
1717
) \
18-
| grep -q "${STATUS_BAD_REQUEST}"
18+
| grep -q "${STATUS_UNPROCESSABLE_ENTITY}"

http-tests/linked-data-templates/custom/POST-spin-constraint-400.sh renamed to http-tests/linked-data-templates/custom/POST-spin-constraint-422.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
initialize_dataset "$BASE_URL_WRITABLE" "../../dataset.trig" "$ENDPOINT_URL_WRITABLE"
66

7-
# expect 400 Bad Request because missing <http://example.com/constrained-predicate> fails SPINConstrainedType constraint validation
7+
# expect 422 Unprocessable Entity because missing <http://example.com/constrained-predicate> fails SPINConstrainedType constraint validation
88

99
(
1010
curl -w "%{http_code}\n" -f -s \
@@ -15,4 +15,4 @@ curl -w "%{http_code}\n" -f -s \
1515
<${BASE_URL_WRITABLE}default-subject-post> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://github.com/AtomGraph/Processor/blob/develop/http-tests/custom#SPINConstrainedType> .
1616
EOF
1717
) \
18-
| grep -q "${STATUS_BAD_REQUEST}"
18+
| grep -q "${STATUS_UNPROCESSABLE_ENTITY}"

http-tests/linked-data-templates/custom/PUT-shacl-constraint-400.sh renamed to http-tests/linked-data-templates/custom/PUT-shacl-constraint-422.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
initialize_dataset "$BASE_URL_WRITABLE" "../../dataset.trig" "$ENDPOINT_URL_WRITABLE"
66

7-
# expect 400 Bad Request because missing <http://example.com/constrained-predicate> fails SHACLConstrainedType constraint validation
7+
# expect 422 Unprocessable Entity because missing <http://example.com/constrained-predicate> fails SHACLConstrainedType constraint validation
88

99
(
1010
curl -w "%{http_code}\n" -f -s \
@@ -16,4 +16,4 @@ curl -w "%{http_code}\n" -f -s \
1616
<${BASE_URL_WRITABLE}default-subject-post> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://github.com/AtomGraph/Processor/blob/develop/http-tests/custom#SHACLConstrainedType> .
1717
EOF
1818
) \
19-
| grep -q "${STATUS_BAD_REQUEST}"
19+
| grep -q "${STATUS_UNPROCESSABLE_ENTITY}"

http-tests/linked-data-templates/custom/PUT-spin-constraint-400.sh renamed to http-tests/linked-data-templates/custom/PUT-spin-constraint-422.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
initialize_dataset "$BASE_URL_WRITABLE" "../../dataset.trig" "$ENDPOINT_URL_WRITABLE"
66

7-
# expect 400 Bad Request because missing <http://example.com/constrained-predicate> fails SPINConstrainedType constraint validation
7+
# expect 422 Unprocessable Entity because missing <http://example.com/constrained-predicate> fails SPINConstrainedType constraint validation
88

99
(
1010
curl -w "%{http_code}\n" -f -s \
@@ -16,4 +16,4 @@ curl -w "%{http_code}\n" -f -s \
1616
<${BASE_URL_WRITABLE}default-subject-post> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://github.com/AtomGraph/Processor/blob/develop/http-tests/custom#SPINConstrainedType> .
1717
EOF
1818
) \
19-
| grep -q "${STATUS_BAD_REQUEST}"
19+
| grep -q "${STATUS_UNPROCESSABLE_ENTITY}"

http-tests/linked-data-templates/ngt/GET-link-headers.sh

100644100755
File mode changed.

http-tests/sparql-protocol/update/POST-directly.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# SPARQL query directly as POST body
3+
# SPARQL update directly as POST body
44

55
(
66
curl -w "%{http_code}\n" -f -s \

src/main/java/com/atomgraph/server/mapper/SHACLConstraintViolationExceptionMapper.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,10 @@ public Response toResponse(SHACLConstraintViolationException ex)
4343
ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest"));
4444
ex.getModel().add(exception.getModel());
4545

46-
// SPINConstraints.addConstraintViolationsRDF(ex.getConstraintViolations(), ex.getModel(), true);
47-
// ResIterator it = ex.getModel().listSubjectsWithProperty(RDF.type, SPIN.ConstraintViolation);
48-
// try
49-
// {
50-
// while (it.hasNext())
51-
// {
52-
// Resource violation = it.next();
53-
// // connect Response to ConstraintViolations
54-
// ex.getModel().add(exception, ResourceFactory.createProperty("http://www.w3.org/ns/prov#wasDerivedFrom"), violation);
55-
// }
56-
// }
57-
// finally
58-
// {
59-
// it.close();
60-
// }
6146
ex.getModel().add(ex.getValidationReport().getModel());
6247

6348
return getResponseBuilder(ex.getModel()).
64-
status(Response.Status.BAD_REQUEST).
49+
status(422). // 422 Unprocessable Entity
6550
build();
6651
}
6752

src/main/java/com/atomgraph/server/mapper/SPINConstraintViolationExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Response toResponse(SPINConstraintViolationException ex)
6565
}
6666

6767
return getResponseBuilder(ex.getModel()).
68-
status(Response.Status.BAD_REQUEST).
68+
status(422). // 422 Unprocessable Entity
6969
build();
7070
}
7171

0 commit comments

Comments
 (0)