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

Only parse $schema during schema validation #171

Merged
merged 3 commits into from
Jan 23, 2024

Commits on Jan 20, 2024

  1. Only parse $schema during schema validation

    Parsing the whole schema can lead to errors for malformed keyword
    values, eg:
    
    ```
    >> JSONSchemer.schema({ 'properties' => '' })
    /Users/dharsha/repos/json_schemer/lib/json_schemer/draft202012/vocab/applicator.rb:224:in `parse': undefined method `each_with_object' for an instance of String (NoMethodError)
    
                value.each_with_object({}) do |(property, subschema), out|
                     ^^^^^^^^^^^^^^^^^
    	from /Users/dharsha/repos/json_schemer/lib/json_schemer/keyword.rb:14:in `initialize'
    ```
    
    Instead, this creates a minimal parseable schema with just the `$schema`
    value, if it's present and a string. That way the meta schema can be
    determined as usual and then used to validate the provided schema.
    
    Addresses: #167
    davishmcclurg committed Jan 20, 2024
    Configuration menu
    Copy the full SHA
    3cd67b9 View commit details
    Browse the repository at this point in the history
  2. Support String and Pathname schema validation

    This aligns the schema generation (`JSONSchemer.schema`) and schema
    validation (`valid_schema?` and `validate_schema`) method interfaces, so
    that they all take the same schema object types.
    davishmcclurg committed Jan 20, 2024
    Configuration menu
    Copy the full SHA
    91d2f2b View commit details
    Browse the repository at this point in the history

Commits on Jan 23, 2024

  1. Allow passing options to schema validation methods

    The default meta schemas don't inherit the provided options, because
    they're initialized with their own options and cached. To override
    validation-time options, they need to be passed directly to the
    validation methods.
    
    This is a little brittle because the validation-time options are listed
    separately to pull them out of the options hash. I couldn't think of a
    better way to split the initialization and validation options.
    davishmcclurg committed Jan 23, 2024
    Configuration menu
    Copy the full SHA
    ebb23fc View commit details
    Browse the repository at this point in the history