Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #995/827e2819 backport][0.25] Improve validation logic #996

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading