-
Notifications
You must be signed in to change notification settings - Fork 66
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
Small refactoring: extract validate_enum and validate_const methods #113
Small refactoring: extract validate_enum and validate_const methods #113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me to what changed for these keywords (enum
and const
) in the new drafts? It doesn't look like they've changed to me, but I could be missing something (looking here: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-enum).
@@ -122,8 +121,8 @@ def validate_instance(instance, &block) | |||
end | |||
end | |||
|
|||
yield error(instance, 'enum') if enum && !enum.include?(data) | |||
yield error(instance, 'const') if schema.key?('const') && schema['const'] != data | |||
validate_enum(instance, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should pass enum
to this method instead:
validate_enum(instance, enum, &block) if enum
yield error(instance, 'enum') if enum && !enum.include?(data) | ||
yield error(instance, 'const') if schema.key?('const') && schema['const'] != data | ||
validate_enum(instance, &block) | ||
validate_const(instance, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. And you could pull out const
above (similar to enum
on line 87):
validate_const(instance, const, &block) if schema.key?('const')
Sure, there is a new nullable boolean property, so you can mark the enum as nullable and it should skip the validation because it accepts Old language:
oneOf:
- type: string
enum:
- ruby
- python
- type: null New type: string
enum:
- ruby
- python
nullable: true |
I don't see |
That is correct. It was removed in OpenAPI 3.1, because you can just use multiple types. |
Closing then people! Thanks |
In order to be able to override how we're validating enums and const we need to first extract it as separate methods, so we're able to take advantage of the inheritance and override that small methods.
This won't affect the current codebase but will allow us to start working on supporting draft 2020-12 based on that.