Skip to content

Commit e68cf74

Browse files
committed
fix: handle query parameter validation in StringValidator
Handle scenarios where QUERY_PARAMETER is validated by using node.asText() to extract string values, ensuring better support for query parameter types.
1 parent c2b719f commit e68cf74

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/src/main/java/com/predic8/membrane/core/openapi/validators/StringValidator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.regex.*;
2525

2626
import static com.predic8.membrane.core.openapi.util.Utils.*;
27+
import static com.predic8.membrane.core.openapi.validators.ValidationContext.ValidatedEntityType.QUERY_PARAMETER;
2728
import static java.lang.String.*;
2829

2930
@SuppressWarnings("rawtypes")
@@ -61,11 +62,14 @@ public ValidationErrors validate(ValidationContext ctx, Object obj) {
6162

6263
String value;
6364
if (obj instanceof JsonNode node) {
64-
if (!JsonNodeType.STRING.equals(node.getNodeType())) {
65+
if (JsonNodeType.STRING.equals(node.getNodeType())) {
66+
value = node.textValue();
67+
} else if (QUERY_PARAMETER.equals(ctx.getValidatedEntityType())) {
68+
value = node.asText();
69+
} else {
6570
errors.add(ctx, format("String expected but got %s of type %s", node, node.getNodeType()));
6671
return errors;
6772
}
68-
value = node.textValue();
6973
} else if (obj instanceof String s) {
7074
value = s;
7175
} else {

0 commit comments

Comments
 (0)