nu_scripts/modules/to-json-schema
Auca Coyan 13a73ab635
🐛 fix more parser errors (#783)
Hi! I reduced some of the errors in the daily CI. Still there are a few
of them, but at least is something

- Added the badge for the `daily.yml` (currently failing)
- removed old `docker` from v0.60
- removed old `git` from auto-generate completions
- removed `nethack` from auto-generate completions (wasn't very useful)
- removed `root` from auto-generate completions (wasn't very useful)
- removed `valgrind` from auto-generate completions (wasn't very useful)
- moved `less` from auto-generate to custom-completions.
- moved `mix` from auto-generate to custom-completions.
- moved `tar` from auto-generate to custom-completions.
- moved `tcpdump` from auto-generate to custom-completions.
- moved `virsh` from auto-generate to custom-completions.
- moved `zef` from auto-generate to custom-completions.
- fixed `base16.nu`
- fixed `from-cpuinfo.nu`
- fixed `from-dmicode.nu`
- fixed `to-number-format.nu`
- fixed `to-json-schema.nu`
2024-03-15 21:10:27 -05:00
..
README.md Simple json schema generator (#577) 2023-08-12 07:17:33 -05:00
to-json-schema.nu 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00

Notes

  • title properties are generated from input property names converting all capital letters to lowercase with space before them like: someImportantKey -> some important key
  • description properties are generated from input property names converting all capital letters to lowercase with space before them and appended doc urls like: someImportantKey -> some important key\nhttps://some/documentation
  • type properties are generated from input property values
  • minimum properties are generated for input properties containing width/ height/size word
  • default properties are generated for input properties not starting with my/sample/example words
  • example properties are generated for input properties starting with my/sample/example words

Example

Input JSON:

{
    "size": "normal",
    "myInput": 1,
    "width": 21,
    "files": ["test.blend", "test.blend"]
}

Output JSON schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "title": "config",
  "description": "A config",
  "type": "object",
  "properties": {
    "size": {
      "title": "size",
      "description": "size\nhttps://my-doc",
      "type": "string",
      "minimum": 0,
      "default": "normal"
    },
    "myInput": {
      "title": "my input",
      "description": "my input\nhttps://my-doc",
      "type": "number",
      "examples": [
        1
      ]
    },
    "width": {
      "title": "width",
      "description": "width\nhttps://my-doc",
      "type": "number",
      "minimum": 0,
      "default": 21
    },
    "files": {
      "title": "files",
      "description": "files\nhttps://my-doc",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "description": "A file\nhttps://my-doc",
        "type": "string"
      },
      "default": [
        "test.blend",
        "test.blend"
      ]
    }
  }
}