Skip to content

Commit

Permalink
Fix invalid JSON Schema (#309)
Browse files Browse the repository at this point in the history
This fixes an [issue reported on
Zulip](https://napari.zulipchat.com/#narrow/stream/309872-plugins/topic/napari.20plugin.20manifest.20schema/near/386669802)
by @seankmartin. Basically there was a small error in the generated
manifest json schema:

```
❯ check-jsonschema --check-metaschema _schema.json
Schema validation errors were encountered.
  _schema.json::$.definitions.ConfigurationProperty.properties.type.anyOf[1].minItems: True is not of type 'integer'
  _schema.json::$.definitions.Draft06JsonSchema.properties.type.anyOf[1].minItems: True is not of type 'integer'
  _schema.json::$.definitions.Draft07JsonSchema.properties.type.anyOf[1].minItems: True is not of type 'integer'
```

The root of the problem is here, where `min_items` is set to `True`
instead of an integer.

https://github.com/napari/npe2/blob/80ca5feb501dd25d36ecf1313f94d80366d25b8e/src/npe2/manifest/contributions/_json_schema.py#L24C3-L24C3

The first commit here adds a check of the schema in CI using
[check-jsonschema](https://github.com/python-jsonschema/check-jsonschema).
Then the second commit should fix the underlying issue.

cc: @nclack
  • Loading branch information
aganders3 authored Aug 24, 2023
1 parent 80ca5fe commit b856dcd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ jobs:
- name: Build schema
run: |
python -m pip install --upgrade pip
pip install -e .[docs]
pip install -e .[docs] check-jsonschema
python -m npe2.manifest.schema > _schema.json
check-jsonschema --check-metaschema _schema.json
- name: Test rendering docs
run: python _docs/render.py
env:
Expand Down Expand Up @@ -122,8 +123,9 @@ jobs:
- name: write schema
run: |
pip install -e .
pip install -e . check-jsonschema
python -m npe2.manifest.schema > schema.json
check-jsonschema --check-metaschema schema.json
- name: Build and publish
run: twine upload dist/*
Expand Down
4 changes: 2 additions & 2 deletions src/npe2/manifest/contributions/_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
]

JsonType = Literal["array", "boolean", "integer", "null", "number", "object", "string"]
JsonTypeArray = conlist(JsonType, min_items=True, unique_items=True)
StringArrayMin1 = conlist(str, unique_items=True, min_items=1)
JsonTypeArray = conlist(JsonType, min_items=1, unique_items=True)
StringArrayMin1 = conlist(str, min_items=1, unique_items=True)
StringArray = conlist(str, unique_items=True)

PY_NAME_TO_JSON_NAME = {
Expand Down

0 comments on commit b856dcd

Please sign in to comment.