SpaceApi / schema

SpaceAPI JSON schema files.
24 stars 14 forks source link

Remove ajv, add spectral #78

Closed gidsi closed 3 years ago

gidsi commented 3 years ago

Fixes #76

https://meta.stoplight.io/docs/spectral/README.md

dbrgn commented 3 years ago

Hm, did the validation work for you?

I did the following changes to the schema v14:

diff --git a/14-draft.json b/14-draft.json
index c0f56d9..8065670 100644
--- a/14-draft.json
+++ b/14-draft.json
@@ -15,8 +15,8 @@
       }
     },
     "space": {
-      "description": "The name of your space",
-      "type": "string"
+      "escription": "The name of your space",
+      "ype": "string"
     },
     "logo": {
       "description": "URL to your space logo",
@@ -117,7 +117,7 @@
             }
           },
           "required": [
-            "open",
+            "pen",
             "closed"
           ]
         }

This includes two unknown fields (that may be OK), a field with neither type nor description (is that OK?) and a "required" reference to a field that does not exist (that should not be OK, but not sure if a schema checker itself can detect this).

The tests pass though without any warnings:

$ npx spectral --fail-severity hint lint 14-draft.json
JSON Schema detected
JSON Schema (loose) detected
JSON Schema Draft 7 detected
No results with a severity of 'hint' or higher found!

The CLI also doesn't complain if the file being checked doesn't even exist:

$ npx spectral --fail-severity hint lint 14-draft-asdklfjalskdfjlkasjdf.json
No results with a severity of 'hint' or higher found!

$ echo $?
0
gidsi commented 3 years ago

Hm, did the validation work for you?

Oh damn, just did the happy path, my fault, i'll have a look

gidsi commented 3 years ago

@dbrgn this is all pain!

There are just two official json-schema validators (spectral and json-schema-linter)

Spectral somehow doesn't report the problems, it might be that you can add more keys and type and description are not required (also you can add required keys that don't exist oO).

json-schema-linter is just an api... and not a nice one (price model and somehow just created for a tool called json buddy), but it reports all problems as expected.

So i've tried the old version of ajv, but it has the exact same issues spectral has.

gidsi commented 3 years ago

we'll stick with ajv