https://github.com/mgrsskls/json-schema-template-validator
https://github.com/mgrsskls/json-schema-template-validator
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mgrsskls/json-schema-template-validator
- Owner: mgrsskls
- Created: 2020-08-14T20:12:25.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-14T21:55:29.000Z (over 4 years ago)
- Last Synced: 2025-01-21T18:51:06.470Z (4 months ago)
- Language: JavaScript
- Size: 86.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON schema template validator
## Idea
Analyzing a template file for used variables and comparing these against a JSON schema.
## Example
E.g. this template
```twig
{{ title }}
-
{{ link.label }}
{% for link in links %}
{% endfor %}
{% if cta %}
{{ cta }}
{% endif %}
```
could be anaylzed like this:
```yaml
- name: title
type: string
required: true
- name: links
type: array
required: true
items:
type: object
properties:
- name: url
type: string
required: true
- name: label
type: string
required: true
- name: cta
type: string
```
This data could be compared with the actual provided schema.
**NOTE:** This makes the assumption that every variable which is not inside an `if` e.g. is required. This is cleaner code, but in fact this is not true as a missing `title` e.g. would not create an error.
## Problems
### What to do about variables where the type is unclear
E.g. `title` and `cta` in the twig file from the example could also be of type `number` or `boolean`.