Comments (4)
Sorry for the delayed response -- I missed this when it was filed.
I think I would tend to solve this with pre-commit run -a
to run on all files.
However, you could use always_run: true
so long as you also set options to control the filenames passed to the hook.
Setting pass_filenames: false
and args: ["path/to/file1.json", "path/to/file2.json"]
should do the trick.
All that said, I'm going to leave this open and see if I can think of a good solution for this use-case.
It makes sense to me that you would want to specify that, for example, schemas/schema1.json
applies to data/data1/**/*.json
, and so forth. It may be that in order to support this, check-jsonschema
would need to support configuration data, directory traversal/globbing, and other features similar to what pre-commit
is doing. But I'm happy to tinker with it if it sounds useful.
from check-jsonschema.
I have continued to think about this issue, and how it could be solved. I want to share some of my thoughts for two reasons:
- to show what I think the usage will look like and let anyone point out potential problems
- to record the plan for myself, in case I don't get back to this for a while
Basically, the configuration data which would be needed is a map from schema filenames to glob paths. The basic plan is to add a JSON config file:
$ check-jsonschema --config .check_jsonschema.json foo/bar/schema.json foo/bar/items/instance1.json ignored-file.txt
where the contents of .check_jsonschema.json
are
{
"schema_map": {
"foo/bar/schema.json": {
"include": ["foo/bar/**/*.json", "foo/baz/items/bar/**/*.yaml"],
"exclude": ["foo/bar/**/schema.json"]
}
}
}
If all of it shakes out as I hope, the result would be pre-commit usage like
- id: check-jsonschema
name: "Check jsonschema on foo/ files"
files: ^foo/
types: [json, yaml]
args: ["--config", ".check_jsonschema.json"]
Naturally, I would also provide a schema and hook for validating your check-jsonschema config! 😉
This is all highly speculative at this point. I haven't started on an implementation at all yet, and I might not be able to take time to work on this anytime soon, but this is the sort of direction I'd like to take things.
from check-jsonschema.
How I solved this, and it works well enough, is to accept the behaviour of pre-commit
, and run on Github Actions pre-commit run check-jsonschema --all-files
. We actually run it with tox
:
[testenv:jsonschema]
skip_install = true
deps =
pre-commit
commands =
pre-commit run check-jsonschema --all-files
and on GitHub Actions:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: json schema validation
run: tox -e jsonschema
So locally you can always execute the command yourself, of course, to check if your changes will affect the validation. Then, if any mistakes will pass the development process, Gihub will scream to let you know.
from check-jsonschema.
I think it does sound useful, as new files may be added all the time so it's not really possible to pass them all in the options. I'll watch this space :) And I have another suggestion I'll file in a separate issue :) THanks!
from check-jsonschema.
Related Issues (20)
- Support for `default.json` for `renovate` HOT 6
- Allow validating YAML with inline yaml-language-server comments HOT 2
- Allow optionally interpreting .json files as JSON5 HOT 4
- Failure resolving ref to anchor within same schema after v0.24.0 HOT 5
- Support new GitHub Actions Runner Scale Sets HOT 2
- Opening concurrent file handles for all instancefiles risks breaching OS limit. HOT 6
- Support ECMAScript unicode-mode RegExp usage for 'pattern' and 'patternProperties' HOT 3
- [BUG] `github-workflows-require-timeout.json`: `timeout-minutes` should allow expressions HOT 4
- Feature request: add line numbers to the output HOT 3
- Update vendored bitbucket schema HOT 1
- Feature request: add file names to the ouptut even if validation is OK HOT 3
- "unexpected keyword argument 'registry'" when validating specific GitHub workflow HOT 4
- Bug: Globs work in my machine but fails on CI HOT 3
- AttributeError not parsing schema correctly. HOT 2
- Cannot validate date-time via the CLI tool HOT 4
- Distribute the check-jsonschema tool in a manner which does not assume a Python environment
- Validation passes for misspelled optional child properties in Google Cloud Build schema HOT 7
- check-gitlab-ci: coverage is not a regex HOT 9
- Check yaml with check-metaschema option HOT 3
- Non-JSON files ignored despite --default-type being set HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from check-jsonschema.