jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

Access to schema fragment from custom format codeblocks #156

Closed jmfernandez closed 4 years ago

jmfernandez commented 5 years ago

Summary

Custom formats codeblocks now receive as second parameter the schema fragment, in case additional attributes are needed to tweak the validation, per schema fragment.

Motivation

In some of our projects we want to tweak custom formats validation based on values from the schema.

References

(none)

jmfernandez commented 5 years ago

I have just added a new test file for custom formats, including the extension proposed in this pull request.

jhthorsen commented 5 years ago

I'm still sceptical to the change, even though I can see the usefulness in the tests. Do you have an example of library written in a different language that does this?

Also: You still haven't run the code through perltidy.

jhthorsen commented 5 years ago

I kind of want to break the custom validation again and do:

$self->$code($value, $path, $schema);

...but I guess it's not worth it.

I'll merge this after it's tidied up and if no-one else objects. (Let me know if you need help running perltidy)

jmfernandez commented 5 years ago

Yes, please. I haven't used perltidy before, so I don't know the steps you usually follow

karenetheridge commented 5 years ago

@jhthorsen I think it would be helpful for users if you created a 'CONTRIBUTING' file in your repository -- this will be shown to users when they create a pull request. In it you can put your guidelines for creating good patches, such as how to run perltidy using the config file you have created -- as this requirement is not presently made known to people before they submit and it catches them by surprise.

jhthorsen commented 5 years ago

@jmfernandez: I use githook-perltidy install which create git hooks that tidy the code for me when I commit. So I would suggest installing that (it will only affect the current repo you run it in) and then add a random space character inside the files and then do git commit -a -m"tidy the code".

https://metacpan.org/pod/distribution/App-githook-perltidy/bin/githook-perltidy#githook-perltidy-install-[-force,-f]

jmfernandez commented 5 years ago

Sorry, past month was very stressing. @jhthorsen I have just had the chance to install githook-perltidy and its hook. After fixing an issue with a locally installed stale perltidy (two years ago version), I was able to commit again the changes (see https://github.com/fairtracks/json-validator/commit/94cba172282bb1610c250413d01c5a651dd3a12c)

jhthorsen commented 4 years ago

I'm going to close this PR, even though I think it's a good idea. I'm closing it because it's in conflict with master and it seems to have gone stale.