Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide JSON Schema for config file #103

Open
mikaello opened this issue Mar 21, 2023 · 1 comment
Open

Provide JSON Schema for config file #103

mikaello opened this issue Mar 21, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mikaello
Copy link

mikaello commented Mar 21, 2023

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
@allburov
Copy link
Member

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 field repo
  • PropertyEq - fields property_key and property_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.

@allburov allburov added enhancement New feature or request help wanted Extra attention is needed labels Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

2 participants