Provide JSON Schema for config file
mikaello opened this issue · comments
To enhance the developer experience and facilitate validation of config in CI/CD pipelines, it would have been nice if it were a JSON Schema to validate the config against. Given a schema, the config file could be validated with e.g. yajsv:
yajsv -s artifactory-cleanup-schema.yaml artifactory-cleanup.yaml
Users of VSCode with the YAML extension (or IntelliJ users natively) could have added this at the top of their config to get auto-complete and documentation:
# yaml-language-server: $schema=https://raw.githubusercontent.com/devopshq/artifactory-cleanup/master/artifactory-cleanup-schema.yaml
(see blog-post about this extension for more info)
Here is a start for such a JSON Schema:
---
"$schema": http://json-schema.org/draft-07/schema#
type: object
properties:
artifactory-cleanup:
type: object
properties:
server:
type: string
format: uri
user:
type: string
password:
type: string
policies:
type: array
items:
type: object
properties:
name:
type: string
rules:
type: array
description:
See all rules in
https://github.com/devopshq/artifactory-cleanup#rules
items:
type: object
properties:
rule:
type: string
name:
type: string
days:
type: integer
count:
type: integer
property_key:
type:
- integer
- string
property_value:
type:
- integer
- string
custom_regexp:
type: string
masks:
type: array
items:
type: string
required:
- rule
additionalProperties: true
required:
- name
- rules
required:
- server
- user
- password
- policies
required:
- artifactory-cleanup
I like the idea!
The problem that I've met before with JSON schema - it doesn't support types based on property value.
For instance
- the rule
Repo
only allows fieldrepo
PropertyEq
- fieldsproperty_key
andproperty_value
- rule: Repo
name: repo.snapshot
- rule: PropertyEq
property_key: key-name
property_value: 1
We need to look at rule
value to determine the applied schema for the object.
While I was typing it, I found recent solution for that - https://json-schema.org/understanding-json-schema/reference/conditionals.html.
Feel free to contribute such generator!
I think we shouldn't contribute just a single json-schema, but provide a script for these who created their own rules.