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

If statements are not correctly parsed #17

Open
Spitfire1900 opened this issue Jan 15, 2019 · 0 comments
Open

If statements are not correctly parsed #17

Spitfire1900 opened this issue Jan 15, 2019 · 0 comments

Comments

@Spitfire1900
Copy link

The attached schema and json, using an if/then statement to enforce a restricted return as a build successful, when in jsonschemalint.com it correctly returns as [2].domain | should be equal to one of the allowed values | "internal.example.com" -- | -- | --

ingest.json

[
	{
		"domain": "example.com",
		"platform": "linux"
	},
	{
		"domain": "example.com",
		"platform": "windows"
	},
	{
		"domain": "internal.example.com",
		"platform": "windows"
	}
]

ingest.schema.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "minItems": 1,
  "uniqueItems": true,
  "items": {
    "required": ["domain", "platform"],
    "properties": {
      "domain": {
        "enum": ["example.com", "internal.example.com"]
      },
      "platform": {
        "enum": ["linux", "windows" ]
      }
    },
    "if": {
      "properties": {
        "platform": {
          "enum": ["windows"]
        }
      }
    }, "then": {
      "properties": {
        "domain": {
          "enum": ["example.com"]
        }
      }
    }
  }
}

build.gradle

import groovy.json.JsonSlurper

defaultTasks 'groupByPlatform'

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.cz.alenkacz.gradle:json-validator:1.2.1"
  }
}

apply plugin: "cz.alenkacz.gradle.jsonvalidator"


ext {
  targetJsonFileame = "ingest.json"
  jsonSchemaFilename = "ingest.schema.json"
}

task validateInputJson(type: cz.alenkacz.gradle.jsonvalidator.ValidateJsonTask) {
  description = "Validates JSON input against the JSON schema."
  group = "JSON Parsing"
  targetJsonFile = file(targetJsonFileame)
  jsonSchema = file(jsonSchemaFilename)
}

Output:

gradlew.bat validateInputJson

BUILD SUCCESSFUL in 32s
1 actionable task: 1 executed

gradle --version

X:\Tools\gradlew\gradlew.bat --version

------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------

Build time:   2018-09-19 18:10:15 UTC
Revision:     b4d8d5d170bb4ba516e88d7fe5647e2323d791dd

Kotlin DSL:   1.0-rc-6
Kotlin:       1.2.61
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_151 (Oracle Corporation 25.151-b12)
OS:           Windows 7 6.1 amd64
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

No branches or pull requests

1 participant