Skip to content

Commit

Permalink
Improve validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed Jun 20, 2024
1 parent 3e641a5 commit 827e281
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pulp-glue/pulp_glue/common/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def validate_schema(self, schema: t.Any, name: str, value: t.Any) -> t.Any:
if value is None and schema.get("nullable", False):
return None

schema_type = schema.get("type", "string")
schema_type = schema.get("type")
allOf = schema.get("allOf")
anyOf = schema.get("anyOf")
oneOf = schema.get("oneOf")
Expand Down Expand Up @@ -343,7 +343,7 @@ def validate_schema(self, schema: t.Any, name: str, value: t.Any) -> t.Any:
found_valid = True
if not found_valid:
raise OpenAPIValidationError(
_("No schema in anyOf validated for {name}.").format(name=name)
_("No schema in oneOf validated for {name}.").format(name=name)
)
elif not_schema:
try:
Expand All @@ -354,17 +354,31 @@ def validate_schema(self, schema: t.Any, name: str, value: t.Any) -> t.Any:
raise OpenAPIValidationError(
_("Forbidden schema for {name} validated.").format(name=name)
)
elif schema_type is None:
# Schema type is not specified.
# JSONField
pass
elif schema_type == "object":
# Serializer
value = self.validate_object(schema, name, value)
elif schema_type == "array":
# ListField
value = self.validate_array(schema, name, value)
elif schema_type == "string":
# CharField
# TextField
# DateTimeField etc.
# ChoiceField
# FielField (binary data)
value = self.validate_string(schema, name, value)
elif schema_type == "integer":
# IntegerField
value = self.validate_integer(schema, name, value)
elif schema_type == "number":
# FloatField
value = self.validate_number(schema, name, value)
elif schema_type == "boolean":
# BooleanField
if not isinstance(value, bool):
raise OpenAPIValidationError(
_("'{name}' is expected to be a boolean.").format(name=name)
Expand Down

0 comments on commit 827e281

Please sign in to comment.