8000 chore: add json schema by Kawacrepe · Pull Request #202 · NodeSecure/report · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: add json schema #202

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

Merged
merged 1 commit into from
Oct 9, 2021
Merged

chore: add json schema #202

merged 1 commit into from
Oct 9, 2021

Conversation

Kawacrepe
Copy link
Member
@Kawacrepe Kawacrepe commented Oct 1, 2021

close #130

This PR was test using the following script:

var Validator = require('jsonschema').Validator;
var v = new Validator();

const jsonschema = {
  "title": "Report configuration",
  "type": "object",
  "properties": {
      "theme": {
          "type": "string",
          "description": "Theme generated",
          "default": "light"
      },
      "report_title": {
          "type": "string",
          "description": "Report title",
          "default": "Default report title"
      },
      "report_logo": {
          "type": "string",
          "description": "Logo",
          "default": "htt
B996
ps://avatars0.githubusercontent.com/u/29552883?s=200&v=4"
      },
      "npm_org_prefix": {
          "type": "string",
          "description": "Prefix of your npm organization"
      },
      "npm_packages": {
          "type": "array",
          "description": "Npm package include in report",
          "items": {
              "type": "string"
          },
          "uniqueItems": true
      },
      "git_url": {
          "type": "string",
          "description": "Github organization url"
      },
      "git_repositories": {
          "type": "array",
          "description": "Git repositories included in report",
          "items": {
              "type": "string"
          },
          "uniqueItems": true
      },
      "charts": {
          "type": "array",
          "items": { "$ref": "#/$defs/chartItem" }
      }
  },
  "$defs": {
      "chartItem": {
        "type": "object",
        "required": [ "name", "display", "interpolation"],
        "properties": {
          "name": {
            "type": "string",
            "description": "chart name"
          },
          "display": {
            "type": "boolean",
            "description": "Does this chart is displayed"
          },
          "interpolation": {
              "type": "string",
              "description": "interpolation"
          },
          "type": {
              "type": "string",
              "description": "Caracteristic representation"
          }
        }
      }
    }
}

const schemaExample = {
  "theme": "dark",
  "report_title": "SlimIO Security Report",
  "report_logo": "https://avatars0.githubusercontent.com/u/29552883?s=200&v=4",
  "npm_org_prefix": "@slimio",
  "npm_packages": [
      "@slimio/addon",
      "@slimio/scheduler",
      "@slimio/config",
      "@slimio/core",
      "@slimio/arg-parser",
      "@slimio/profiles",
      "@slimio/queue",
      "@slimio/sqlite-transaction",
      "@slimio/alert",
      "@slimio/metrics",
      "@slimio/units",
      "@slimio/ipc",
      "@slimio/safe-emitter"
  ],
  "git_url": "https://github.com/SlimIO",
  "git_repositories": [
      "Aggregator",
      "Alerting",
      "Socket",
      "Gate",
      "ihm"
  ],
  "charts": [
      {
          "name": "Extensions",
          "display": true,
          "interpolation": "d3.interpolateRainbow"
      },
      {
          "name": "Licenses",
          "display": true,
          "interpolation": "d3.interpolateCool"
      },
      {
          "name": "Warnings",
          "display": true,
          "type": "horizontalBar",
          "interpolation": "d3.interpolateInferno"
      },
      {
          "name": "Flags",
          "display": true,
          "type": "horizontalBar",
          "interpolation": "d3.interpolateSinebow"
      }
  ]
}

console.log(v.validate(schemaExample, jsonschema).valid)
// return true

@fraxken fraxken merged commit 92ca635 into master Oct 9, 2021
@fraxken fraxken deleted the chore--add-jsonschema branch March 18, 2022 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Création d'un Schéma JSON pour la configuration
2 participants
0