From 415e905682976e712279701b5d3dbf6661a23baa Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 11:20:46 +0100 Subject: [PATCH 1/8] add validation modes and support for the parameters meta schema --- .../validation/config/ValidationConfig.groovy | 11 +++++ .../validators/JsonSchemaValidator.groovy | 45 ++++++++++++++----- .../1.0/parameters_meta_schema.json | 1 + 3 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 7dc6b64..c40d77f 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -21,6 +21,7 @@ class ValidationConfig { final public String parametersSchema final public Boolean showHiddenParams final public Integer maxErrValSize = 150 + final public String mode = "unlimited" final public HelpConfig help final public SummaryConfig summary @@ -47,6 +48,16 @@ class ValidationConfig { help = new HelpConfig(config.help as Map ?: [:], params, monochromeLogs, showHiddenParams) summary = new SummaryConfig(config.summary as Map ?: [:], monochromeLogs) + if(config.containsKey("mode")) { + def List allowedModes = ["limited", "unlimited"] + if(allowedModes.contains(config.mode)) { + mode = config.mode + } else { + log.warn("Detected an unsupported mode in `validation.mode`, supported options are: ${allowedModes}, defaulting to `${mode}`") + } + log.debug("Set nf-schema validation mode to `${mode}`") + } + if(config.ignoreParams && !(config.ignoreParams instanceof List)) { throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values") } diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index 6c12045..6f316ab 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -9,7 +9,11 @@ import dev.harrel.jsonschema.EvaluatorFactory import dev.harrel.jsonschema.FormatEvaluatorFactory import dev.harrel.jsonschema.JsonNode import dev.harrel.jsonschema.providers.OrgJsonNode +import dev.harrel.jsonschema.SchemaResolver +import nextflow.Nextflow +import java.nio.file.Path +import java.nio.file.Paths import java.util.regex.Pattern import java.util.regex.Matcher @@ -28,33 +32,50 @@ import nextflow.validation.validators.evaluators.CustomEvaluatorFactory @Slf4j public class JsonSchemaValidator { - private ValidatorFactory validator - private Pattern uriPattern = Pattern.compile('^#/(\\d*)?/?(.*)$') private ValidationConfig config JsonSchemaValidator(ValidationConfig config) { - this.validator = new ValidatorFactory() - .withJsonNodeFactory(new OrgJsonNode.Factory()) - // .withDialect() // TODO define the dialect - .withEvaluatorFactory(EvaluatorFactory.compose(new CustomEvaluatorFactory(config), new FormatEvaluatorFactory())) this.config = config } private Tuple2,List> validateObject(JsonNode input, String validationType, Object rawJson, String schemaString) { def JSONObject schema = new JSONObject(schemaString) def String draft = getValueFromJsonPointer("#/\$schema", schema) - if(draft != "https://json-schema.org/draft/2020-12/schema") { - log.error("""Failed to load the meta schema: - The used schema draft (${draft}) is not correct, please use \"https://json-schema.org/draft/2020-12/schema\" instead. + def String draft2020_12 = "https://json-schema.org/draft/2020-12/schema" + if(config.mode == "limited") { + if(validationType == "parameter" && !draft.matches("https://github.com/nextflow-io/schema-spec/.*/parameters_meta_schema.json")) { + log.error("""Failed to load meta schema: + Using '${draft}' for parameter JSON schemas is not allowed in limited mode. Please use a schema that matches the following regex instead: + `https://github.com/nextflow-io/schema-spec/.*/parameters_meta_schema.json` + """) + throw new SchemaValidationException("", []) + } else if(validationType != "parameter" && draft != draft2020_12) { + log.error("""Failed to load the meta schema: + The used schema draft (${draft}) is not correct, please use \"${draft2020_12}\" instead. - If you are a pipeline developer, check our migration guide for more information: https://nextflow-io.github.io/nf-schema/latest/migration_guide/ - If you are a pipeline user, revert back to nf-validation to avoid this error: https://www.nextflow.io/docs/latest/plugins.html#using-plugins, i.e. set `plugins { id 'nf-validation@1.1.3' }` in your `nextflow.config` file - """) - throw new SchemaValidationException("", []) + """) + throw new SchemaValidationException("", []) + } } + + def SchemaResolver resolver = (String uri) -> { + switch(uri) { + // TODO Change the base URL once the meta schema has been officially released + case "https://github.com/nextflow-io/schema-spec/raw/refs/heads/main/parameters_meta_schema.json" -> + SchemaResolver.Result.fromString(Nextflow.file(getClass().getResource("/schemas/parameters/1.0/parameters_meta_schema.json").getFile()).text) + default -> SchemaResolver.Result.empty() + } + } + + def ValidatorFactory validator = new ValidatorFactory() + .withJsonNodeFactory(new OrgJsonNode.Factory()) + .withSchemaResolver(resolver) + .withEvaluatorFactory(EvaluatorFactory.compose(new CustomEvaluatorFactory(config), new FormatEvaluatorFactory())) - def Validator.Result result = this.validator.validate(schema, input) + def Validator.Result result = validator.validate(schema, input) def List errors = [] result.getErrors().each { error -> def String errorString = error.getError() diff --git a/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json b/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json new file mode 100644 index 0000000..09df35b --- /dev/null +++ b/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json @@ -0,0 +1 @@ +{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://nextflow.io","title":"NextflowSchemaMeta-schema","description":"Meta-schematovalidateNextflowparameterschemafiles","type":"object","properties":{"$schema":{"title":"schema","type":"string","minLength":1},"$id":{"title":"IDURI","type":"string","minLength":1},"title":{"title":"Title","type":"string","minLength":1},"description":{"title":"Description","type":"string","minLength":1},"type":{"title":"Topleveltype","type":"string","const":"object"},"$defs":{"title":"Parametergroups","type":"object","patternProperties":{"^.*$":{"type":"object","required":["title","type","properties"],"properties":{"title":{"type":"string","minLength":1},"type":{"const":"object"},"fa_icon":{"type":"string","pattern":"^fa"},"description":{"type":"string"},"required":{"type":"array"},"properties":{"$ref":"#/$defs/parameterOptions"},"dependentRequired":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"},"uniqueItems":true,"default":[]}}}}}},"properties":{"$ref":"#/$defs/parameterOptions"},"dependentRequired":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"},"uniqueItems":true,"default":[]}},"allOf":{"title":"Combinedefinitiongroups","type":"array","items":{"type":"object","required":["$ref"],"properties":{"$ref":{"type":"string","pattern":"^#/\\$defs/[^/]+$"}}}}},"required":["$schema","$id","title","description","type"],"$defs":{"typeAnnotation":{"type":"string","enum":["string","boolean","integer","number","null"]},"allTypes":{"type":["integer","boolean","string","number","null"]},"nonNegativeInteger":{"type":"integer","minimum":0},"parameterOptions":{"type":"object","patternProperties":{"^.*$":{"type":"object","allOf":[{"$ref":"#/$defs/standardKeywords"},{"$ref":"#/$defs/customKeywords"}],"required":["type","description"],"unevaluatedProperties":false}}},"standardKeywords":{"type":"object","description":"AllowedstandardJSONSchemaproperties.","properties":{"type":{"description":"Thetypeoftheparametervalue.Canbeoneormoreofthese:`['integer','boolean','number','string','null']`","anyOf":[{"$ref":"#/$defs/typeAnnotation"},{"type":"array","items":{"$ref":"#/$defs/typeAnnotation"}}]},"format":{"type":"string","description":"Theformatofaparametervaluewiththe'string'type.Thisisusedforadditionalvalidationonthestructureofthevalue.","enum":["file-path","directory-path","path","file-path-pattern","date-time","date","time","email","uri","regex"]},"pattern":{"type":"string","format":"regex","minLength":1,"description":"Checkaparametervalueof'string'typeagainstaregexpattern"},"description":{"type":"string","description":"Thedescriptionofthecurrentparameter"},"default":{"$ref":"#/$defs/allTypes","description":"Specifiesadefaultvaluetouseforthisparameter"},"examples":{"type":"array","items":{"$ref":"#/$defs/allTypes"},"description":"Alistofexamplesforthecurrentparameter"},"deprecated":{"type":"boolean","description":"Statesthattheparameterisdeprecated.Pleaseprovideanicedeprecationmessageusing'errorMessage'"},"minLength":{"$ref":"#/$defs/nonNegativeInteger","description":"Theminimumlengtha'string'parametervalueshouldbe"},"maxLength":{"$ref":"#/$defs/nonNegativeInteger","description":"Themaximumlengtha'string'parametervalueshouldbe"},"minimum":{"type":"number","description":"Themimimumvaluean'integer'or'number'parametervalueshouldbe"},"exclusiveMinimum":{"type":"number","description":"Theexclusivemimimumvaluean'integer'or'number'parametervalueshouldbe"},"maximum":{"type":"number","description":"Themaximumvaluean'integer'or'number'parametervalueshouldbe"},"exclusiveMaximum":{"type":"number","description":"Theexclusivemaximumvaluean'integer'or'number'parametervalueshouldbe"},"multipleOf":{"type":"number","description":"The'integer'or'number'parametervalueshouldbeamultipleofthisvalue"},"enum":{"type":"array","uniqueItems":true,"items":{"$ref":"#/$defs/allTypes"},"description":"Theparametervalueshouldbeoneofthevaluesspecifiedinthisenumarray"},"const":{"$ref":"#/$defs/allTypes","description":"Theparametervalueshouldbeequaltothisvalue"}}},"customKeywords":{"type":"object","description":"AdditionalcustomJSONSchemaproperties.","properties":{"errorMessage":{"type":"string","minLength":1,"description":"NONSTANDARDOPTION:Thecustomerrormessagetodisplayincasevalidationagainstthisparameterfails.Canalsobeusedasadeprecationmessageif'deprecated'istrue"},"exists":{"type":"boolean","description":"NONSTANDARDOPTION:Checkifafileexists.Thisparametervalueneedstobea`string`typewithoneoftheseformats:`['path','file-path','directory-path','file-path-pattern']`"},"schema":{"type":"string","minLength":1,"pattern":"\\.json$","description":"NONSTANDARDOPTION:Checkthegivenfileagainstaschemapassedtothiskeyword.Willonlyworkwhentypeis`string`andformatis`path`or`file-path`"},"help_text":{"type":"string","description":"NONSTANDARDOPTION:Amoredetailedhelptext"},"fa_icon":{"type":"string","pattern":"^fa","description":"NONSTANDARDOPTION:Afontawesomeicontouseinthenf-coreparameterdocumentation"},"hidden":{"type":"boolean","description":"NONSTANDARDOPTION:Hidethisparameterfromthehelpmessageanddocumentation"},"mimetype":{"type":"string","description":"NONSTANDARDOPTION:TheMIMEtypeoftheparametervalue","deprecated":true,"errorMessage":"The'mimetype'keywordisdeprecated.Use'pattern'or'format'instead."}},"dependentSchemas":{"exists":{"$comment":"Thischecksifthetypeisa'string'andtheformatcorrespondstoafileordirectorywhen'exists'isused.","properties":{"type":{"const":"string"},"format":{"enum":["path","file-path","file-path-pattern","directory-path"]}}},"schema":{"$comment":"Thischecksifthetypeisa'string'andtheformatis'path'or'file-path'","properties":{"type":{"const":"string"},"format":{"enum":["path","file-path"]}}}}}}} \ No newline at end of file From aeab3ee8f9c6822847b765f341cc39bc4dedf6bb Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 11:28:07 +0100 Subject: [PATCH 2/8] update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 531877c..213650d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,11 @@ ## New features -1. Added a new configuration option: `validation.maxErrValSize` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. +1. Added 2 new configuration options: + - `validation.maxErrValSize` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. + - `validation.mode` which sets the validation mode. Possible options are `limited` and `unlimited`. In `limited` mode the JSON schemas for parameters will be limited to the official Nextflow specs to ensure compatibility with nf-core tooling, Seqera platform and other tools. These restrictions are not set when using `unlimited` mode. The default is set to `unlimited` to retain backwards compatibility. 2. Added a new function: `validate()` that can be used to validate any data structure using a JSON schema. +3. Add support for the official Nextflow JSON schema specification for parameters located in https://github.com/nextflow-io/schema-spec ## Bug fixes From 360e2cb3aa63fcd2a38520a6adc66eeeff966707 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 13:05:40 +0100 Subject: [PATCH 3/8] make custom schema checker more flexible and extendable --- .../validators/JsonSchemaValidator.groovy | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index e99457e..97bcaf9 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -32,21 +32,37 @@ import nextflow.validation.validators.evaluators.CustomEvaluatorFactory @Slf4j public class JsonSchemaValidator { + // TODO Change the base URL once the meta schema has been officially released + final private Map supportedCustomParameterDrafts = [ + "https://github.com/nextflow-io/schema-spec/raw/refs/heads/main/parameters_meta_schema.json": "/schemas/parameters/1.0/parameters_meta_schema.json" + ] + private ValidationConfig config + private ValidatorFactory validator JsonSchemaValidator(ValidationConfig config) { + def SchemaResolver resolver = (String uri) -> { + if(supportedCustomParameterDrafts.containsKey(uri)) { + return SchemaResolver.Result.fromString(Nextflow.file(getClass().getResource(supportedCustomParameterDrafts[uri]).getFile()).text) + } + return SchemaResolver.Result.empty() + } + + this.validator = new ValidatorFactory() + .withJsonNodeFactory(new OrgJsonNode.Factory()) + .withSchemaResolver(resolver) + .withEvaluatorFactory(EvaluatorFactory.compose(new CustomEvaluatorFactory(config), new FormatEvaluatorFactory())) this.config = config } - private Tuple2,List> validateObject(JsonNode input, String validationType, Object rawJson, String schemaString) { def JSONObject schema = new JSONObject(schemaString) def String draft = getValueFromJsonPointer("#/\$schema", schema) def String draft2020_12 = "https://json-schema.org/draft/2020-12/schema" if(config.mode == "limited") { - if(validationType == "parameter" && !draft.matches("https://github.com/nextflow-io/schema-spec/.*/parameters_meta_schema.json")) { + if(validationType == "parameter" && !supportedCustomParameterDrafts.containsKey(draft)) { log.error("""Failed to load meta schema: - Using '${draft}' for parameter JSON schemas is not allowed in limited mode. Please use a schema that matches the following regex instead: - `https://github.com/nextflow-io/schema-spec/.*/parameters_meta_schema.json` + Using '${draft}' for parameter JSON schemas is not allowed in limited mode. Please use one the following meta schemas instead: +${supportedCustomParameterDrafts.collect{ url, cachedSchema -> " - ${url}"}.join("\n") } """) throw new SchemaValidationException("", []) } else if(validationType != "parameter" && draft != draft2020_12) { @@ -60,22 +76,8 @@ public class JsonSchemaValidator { throw new SchemaValidationException("", []) } } - - def SchemaResolver resolver = (String uri) -> { - switch(uri) { - // TODO Change the base URL once the meta schema has been officially released - case "https://github.com/nextflow-io/schema-spec/raw/refs/heads/main/parameters_meta_schema.json" -> - SchemaResolver.Result.fromString(Nextflow.file(getClass().getResource("/schemas/parameters/1.0/parameters_meta_schema.json").getFile()).text) - default -> SchemaResolver.Result.empty() - } - } - - def ValidatorFactory validator = new ValidatorFactory() - .withJsonNodeFactory(new OrgJsonNode.Factory()) - .withSchemaResolver(resolver) - .withEvaluatorFactory(EvaluatorFactory.compose(new CustomEvaluatorFactory(config), new FormatEvaluatorFactory())) - def Validator.Result result = validator.validate(schema, input) + def Validator.Result result = this.validator.validate(schema, input) def List errors = [] result.getErrors().each { error -> def String errorString = error.getError() From ced78b7bf47338bd3bdd0287d484f1d15f22bad5 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 13:33:32 +0100 Subject: [PATCH 4/8] fix issue with a missing error message --- .../validators/JsonSchemaValidator.groovy | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index 97bcaf9..322b723 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -58,23 +58,21 @@ public class JsonSchemaValidator { def JSONObject schema = new JSONObject(schemaString) def String draft = getValueFromJsonPointer("#/\$schema", schema) def String draft2020_12 = "https://json-schema.org/draft/2020-12/schema" - if(config.mode == "limited") { - if(validationType == "parameter" && !supportedCustomParameterDrafts.containsKey(draft)) { - log.error("""Failed to load meta schema: + if(config.mode == "limited" && validationType == "parameter" && !supportedCustomParameterDrafts.containsKey(draft)) { + log.error("""Failed to load meta schema: Using '${draft}' for parameter JSON schemas is not allowed in limited mode. Please use one the following meta schemas instead: ${supportedCustomParameterDrafts.collect{ url, cachedSchema -> " - ${url}"}.join("\n") } - """) - throw new SchemaValidationException("", []) - } else if(validationType != "parameter" && draft != draft2020_12) { - log.error("""Failed to load the meta schema: + """) + throw new SchemaValidationException("", []) + } else if(draft != draft2020_12 && !supportedCustomParameterDrafts.containsKey(draft)) { + log.error("""Failed to load the meta schema: The used schema draft (${draft}) is not correct, please use \"${draft2020_12}\" instead. - If you are a pipeline developer, check our migration guide for more information: https://nextflow-io.github.io/nf-schema/latest/migration_guide/ - If you are a pipeline user, revert back to nf-validation to avoid this error: https://www.nextflow.io/docs/latest/plugins.html#using-plugins, i.e. set `plugins { id 'nf-validation@1.1.3' }` in your `nextflow.config` file - """) - throw new SchemaValidationException("", []) - } + """) + throw new SchemaValidationException("", []) } def Validator.Result result = this.validator.validate(schema, input) From ae7ac9ef832a32d18f7820d8306756e37250f382 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 13:33:40 +0100 Subject: [PATCH 5/8] add tests --- .../validation/ValidateParametersTest.groovy | 106 +++++++ ...tflow_schema_custom_param_meta_schema.json | 278 ++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 plugins/nf-schema/src/testResources/nextflow_schema_custom_param_meta_schema.json diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index 513c60c..36742a4 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1435,4 +1435,110 @@ class ValidateParametersTest extends Dsl2Spec{ error.message.contains("* --input (src/testRe..._extension): \"src/testResources/wrong_samplesheet_with_a_super_long_name.and_a_weird_extension\" does not match regular expression [^\\S+\\.(csv|tsv|yaml|json)\$]") !stdout } + + def 'should fail with draft 2020_12 in limited mode' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = ["validation": [ + "mode": "limited" + ]] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + def error = thrown(SchemaValidationException) + !stdout + } + + def 'should validate with custom parameter meta schema in limited mode' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.input = 'src/testResources/correct.csv' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = ["validation": [ + "mode": "limited" + ]] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + noExceptionThrown() + !stdout + } + + def 'should validate with custom parameter meta schema in unlimited mode' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.input = 'src/testResources/correct.csv' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = ["validation": [ + "mode": "unlimited" + ]] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + noExceptionThrown() + !stdout + } + + def 'should validate with custom parameter meta schema in limited mode - failure' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = ["validation": [ + "mode": "limited", + "monochromeLogs": true + ]] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + def error = thrown(SchemaValidationException) + error.message == """The following invalid input values have been detected: + +* Missing required parameter(s): input, outdir + +""" + !stdout + } } \ No newline at end of file diff --git a/plugins/nf-schema/src/testResources/nextflow_schema_custom_param_meta_schema.json b/plugins/nf-schema/src/testResources/nextflow_schema_custom_param_meta_schema.json new file mode 100644 index 0000000..608a86d --- /dev/null +++ b/plugins/nf-schema/src/testResources/nextflow_schema_custom_param_meta_schema.json @@ -0,0 +1,278 @@ +{ + "$schema": "https://github.com/nextflow-io/schema-spec/raw/refs/heads/main/parameters_meta_schema.json", + "$id": "https://raw.githubusercontent.com/nf-core/testpipeline/master/nextflow_schema.json", + "title": "nf-core/testpipeline pipeline parameters", + "description": "this is a test", + "type": "object", + "$defs": { + "input_output_options": { + "title": "Input/output options", + "type": "object", + "fa_icon": "fas fa-terminal", + "description": "Define where the pipeline should find input data and save output data.", + "required": ["input", "outdir"], + "properties": { + "input": { + "type": "string", + "format": "file-path", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", + "description": "Path to comma-separated file containing information about the samples in the experiment.", + "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", + "fa_icon": "fas fa-file-csv" + }, + "outdir": { + "type": "string", + "format": "directory-path", + "description": "The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.", + "fa_icon": "fas fa-folder-open" + }, + "email": { + "type": "string", + "description": "Email address for completion summary.", + "format": "email", + "fa_icon": "fas fa-envelope", + "help_text": "Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits. If set in your user config file (`~/.nextflow/config`) then you don't need to specify this on the command line for every run." + }, + "multiqc_title": { + "type": "string", + "description": "MultiQC report title. Printed as page header, used for filename if not otherwise specified.", + "fa_icon": "fas fa-file-signature" + } + } + }, + "reference_genome_options": { + "title": "Reference genome options", + "type": "object", + "fa_icon": "fas fa-dna", + "description": "Reference genome related files and options required for the workflow.", + "properties": { + "genome": { + "type": "string", + "description": "Name of iGenomes reference.", + "fa_icon": "fas fa-book", + "help_text": "If using a reference genome configured in the pipeline using iGenomes, use this parameter to give the ID for the reference. This is then used to build the full paths for all required reference genome files e.g. `--genome GRCh38`. \n\nSee the [nf-core website docs](https://nf-co.re/usage/reference_genomes) for more details." + }, + "fasta": { + "type": "string", + "format": "file-path", + "pattern": "^\\S+\\.fn?a(sta)?(\\.gz)?$", + "description": "Path to FASTA genome file.", + "help_text": "This parameter is *mandatory* if `--genome` is not specified. If you don't have a BWA index available this will be generated for you automatically. Combine with `--save_reference` to save BWA index for future runs.", + "fa_icon": "far fa-file-code" + }, + "igenomes_base": { + "type": "string", + "format": "directory-path", + "description": "Directory / URL base for iGenomes references.", + "default": "s3://ngi-igenomes/igenomes", + "fa_icon": "fas fa-cloud-download-alt", + "hidden": true + }, + "igenomes_ignore": { + "type": "boolean", + "description": "Do not load the iGenomes reference config.", + "fa_icon": "fas fa-ban", + "hidden": true, + "help_text": "Do not load `igenomes.config` when running the pipeline. You may choose this option if you observe clashes between custom parameters and those supplied in `igenomes.config`." + } + } + }, + "institutional_config_options": { + "title": "Institutional config options", + "type": "object", + "fa_icon": "fas fa-university", + "description": "Parameters used to describe centralised config profiles. These should not be edited.", + "help_text": "The centralised nf-core configuration profiles use a handful of pipeline parameters to describe themselves. This information is then printed to the Nextflow log when you run a pipeline. You should not need to change these values when you run a pipeline.", + "properties": { + "custom_config_version": { + "type": "string", + "description": "Git commit id for Institutional configs.", + "default": "master", + "hidden": true, + "fa_icon": "fas fa-users-cog" + }, + "custom_config_base": { + "type": "string", + "description": "Base directory for Institutional configs.", + "default": "https://raw.githubusercontent.com/nf-core/configs/master", + "hidden": true, + "help_text": "If you're running offline, Nextflow will not be able to fetch the institutional config files from the internet. If you don't need them, then this is not a problem. If you do need them, you should download the files from the repo and tell Nextflow where to find them with this parameter.", + "fa_icon": "fas fa-users-cog" + }, + "config_profile_name": { + "type": "string", + "description": "Institutional config name.", + "hidden": true, + "fa_icon": "fas fa-users-cog" + }, + "config_profile_description": { + "type": "string", + "description": "Institutional config description.", + "hidden": true, + "fa_icon": "fas fa-users-cog" + }, + "config_profile_contact": { + "type": "string", + "description": "Institutional config contact information.", + "hidden": true, + "fa_icon": "fas fa-users-cog" + }, + "config_profile_url": { + "type": "string", + "description": "Institutional config URL link.", + "hidden": true, + "fa_icon": "fas fa-users-cog" + } + } + }, + "max_job_request_options": { + "title": "Max job request options", + "type": "object", + "fa_icon": "fab fa-acquisitions-incorporated", + "description": "Set the top limit for requested resources for any single job.", + "help_text": "If you are running on a smaller system, a pipeline step requesting more resources than are available may cause the Nextflow to stop the run with an error. These options allow you to cap the maximum resources requested by any single job so that the pipeline will run on your system.\n\nNote that you can not _increase_ the resources requested by any job using these options. For that you will need your own configuration file. See [the nf-core website](https://nf-co.re/usage/configuration) for details.", + "properties": { + "max_cpus": { + "type": "integer", + "description": "Maximum number of CPUs that can be requested for any single job.", + "default": 16, + "fa_icon": "fas fa-microchip", + "hidden": true, + "help_text": "Use to set an upper-limit for the CPU requirement for each process. Should be an integer e.g. `--max_cpus 1`" + }, + "max_memory": { + "type": "string", + "description": "Maximum amount of memory that can be requested for any single job.", + "default": "128.GB", + "fa_icon": "fas fa-memory", + "pattern": "^\\d+(\\.\\d+)?\\.?\\s*(K|M|G|T)?B$", + "hidden": true, + "help_text": "Use to set an upper-limit for the memory requirement for each process. Should be a string in the format integer-unit e.g. `--max_memory '8.GB'`" + }, + "max_time": { + "type": "string", + "description": "Maximum amount of time that can be requested for any single job.", + "default": "240.h", + "fa_icon": "far fa-clock", + "pattern": "^(\\d+\\.?\\s*(s|m|h|day)\\s*)+$", + "hidden": true, + "help_text": "Use to set an upper-limit for the time requirement for each process. Should be a string in the format integer-unit e.g. `--max_time '2.h'`" + } + } + }, + "generic_options": { + "title": "Generic options", + "type": "object", + "fa_icon": "fas fa-file-import", + "description": "Less common options for the pipeline, typically set in a config file.", + "help_text": "These options are common to all nf-core pipelines and allow you to customise some of the core preferences for how the pipeline runs.\n\nTypically these options would be set in a Nextflow config file loaded for all pipeline runs, such as `~/.nextflow/config`.", + "properties": { + "help": { + "type": ["string", "boolean"], + "description": "Display help text.", + "fa_icon": "fas fa-question-circle", + "hidden": true + }, + "publish_dir_mode": { + "type": "string", + "default": "copy", + "description": "Method used to save pipeline results to output directory.", + "help_text": "The Nextflow `publishDir` option specifies which intermediate files should be saved to the output directory. This option tells the pipeline what method should be used to move these files. See [Nextflow docs](https://www.nextflow.io/docs/latest/process.html#publishdir) for details.", + "fa_icon": "fas fa-copy", + "enum": ["symlink", "rellink", "link", "copy", "copyNoFollow", "move"], + "hidden": true + }, + "email_on_fail": { + "type": "string", + "description": "Email address for completion summary, only when pipeline fails.", + "fa_icon": "fas fa-exclamation-triangle", + "pattern": "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$", + "help_text": "An email address to send a summary email to when the pipeline is completed - ONLY sent if the pipeline does not exit successfully.", + "hidden": true + }, + "plaintext_email": { + "type": "boolean", + "description": "Send plain-text email instead of HTML.", + "fa_icon": "fas fa-remove-format", + "hidden": true + }, + "max_multiqc_email_size": { + "type": "string", + "description": "File size limit when attaching MultiQC reports to summary emails.", + "pattern": "^\\d+(\\.\\d+)?\\.?\\s*(K|M|G|T)?B$", + "default": "25.MB", + "fa_icon": "fas fa-file-upload", + "hidden": true + }, + "monochrome_logs": { + "type": "boolean", + "description": "Do not use coloured log outputs.", + "fa_icon": "fas fa-palette", + "hidden": true + }, + "multiqc_config": { + "type": "string", + "description": "Custom config file to supply to MultiQC.", + "fa_icon": "fas fa-cog", + "hidden": true + }, + "tracedir": { + "type": "string", + "description": "Directory to keep pipeline Nextflow logs and reports.", + "default": "${params.outdir}/pipeline_info", + "fa_icon": "fas fa-cogs", + "hidden": true + }, + "validate_params": { + "type": "boolean", + "description": "Boolean whether to validate parameters against the schema at runtime", + "default": true, + "fa_icon": "fas fa-check-square", + "hidden": true + }, + "validationShowHiddenParams": { + "type": "boolean", + "fa_icon": "far fa-eye-slash", + "description": "Show all params when using `--help`", + "hidden": true, + "help_text": "By default, parameters set as _hidden_ in the schema are not shown on the command line when a user runs with `--help`. Specifying this option will tell the pipeline to show all parameters." + }, + "enable_conda": { + "type": "boolean", + "description": "Run this workflow with Conda. You can also use '-profile conda' instead of providing this parameter.", + "hidden": true, + "fa_icon": "fas fa-bacon" + }, + "testCamelCase": { + "type": "string", + "description": "A camelCase param", + "hidden": true + + } + }, + "patternProperties": { + "^pattern_[a-z]+$": { + "type": "string", + "description": "A pattern property parameter" + } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/input_output_options" + }, + { + "$ref": "#/$defs/reference_genome_options" + }, + { + "$ref": "#/$defs/institutional_config_options" + }, + { + "$ref": "#/$defs/max_job_request_options" + }, + { + "$ref": "#/$defs/generic_options" + } + ] +} From 501fd1584a4516b5d217a7d18fc3d860854016b1 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 13:58:54 +0100 Subject: [PATCH 6/8] update docs --- docs/configuration/configuration.md | 11 +++++++++++ docs/nextflow_schema/nextflow_schema_specification.md | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 2fa99b7..c2bd459 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -30,6 +30,17 @@ validation.parametersSchema = "path/to/schema.json" // default "nextflow_schema. This option can either be a path relative to the root of the pipeline directory or a full path to the JSON schema (Be wary to not use hardcoded local paths to ensure your pipeline will keep working on other systems) +## mode + +This option can be used to set the validation mode for parameters. There are two valid options: + +- `unlimited`: No restrictions apply on the validation of parameters. All keywords and schema structures available in [draft 2020-12](https://json-schema.org/draft/2020-12) can be used freely. +- `limited`: Limits the usage of keywords and schema structures for parameter validation to a subset of [draft 2020-12](https://json-schema.org/draft/2020-12). Enabling this mode will ensure compatibility with nf-core tooling, Seqera platform and others. The specified `$schema` inside of the parameters JSON schema needs to be set to the [official Nextflow meta schema](https://github.com/nextflow-io/schema-spec) for parameters. + +```groovy +validation.mode = "limited|unlimited" // default: "limited" +``` + ## monochromeLogs This option can be used to turn of the colored logs from nf-validation. This can be useful if you run a Nextflow pipeline in an environment that doesn't support colored logging. diff --git a/docs/nextflow_schema/nextflow_schema_specification.md b/docs/nextflow_schema/nextflow_schema_specification.md index f91ddcd..d839e85 100644 --- a/docs/nextflow_schema/nextflow_schema_specification.md +++ b/docs/nextflow_schema/nextflow_schema_specification.md @@ -82,7 +82,7 @@ However, they will be displayed as ungrouped in tools working off the schema. ## Nested parameters -!!! example "New feature in v2.1.0" +!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" Nextflow config allows parameters to be nested as objects, for example: @@ -397,6 +397,8 @@ Example usage is as follows: ### `mimetype` +!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" + MIME type for a file path. Setting this value informs downstream tools about what _kind_ of file is expected. Should only be set when `format` is `file-path`. @@ -465,6 +467,8 @@ Specify a minimum / maximum value for an integer or float number length with `mi ## Array-specific keys +!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" + ### `uniqueItems` All items in the array should be unique. From 1773ce49e52f6e16fa46310dde1b0e812bb60679 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Feb 2025 14:05:38 +0100 Subject: [PATCH 7/8] remove old meta schema and reintroduce spaces in descriptions --- parameters_meta_schema.json | 155 ------------------ .../1.0/parameters_meta_schema.json | 2 +- 2 files changed, 1 insertion(+), 156 deletions(-) delete mode 100644 parameters_meta_schema.json diff --git a/parameters_meta_schema.json b/parameters_meta_schema.json deleted file mode 100644 index 5662fd4..0000000 --- a/parameters_meta_schema.json +++ /dev/null @@ -1,155 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://nextflow.io", - "title": "Nextflow Schema Meta-schema", - "description": "Meta-schema to validate Nextflow parameter schema files", - "type": "object", - "properties": { - "$schema": { - "title": "schema", - "type": "string", - "minLength": 1 - }, - "$id": { - "title": "ID URI", - "type": "string", - "minLength": 1 - }, - "title": { - "title": "Title", - "type": "string", - "minLength": 1 - }, - "description": { - "title": "Description", - "type": "string", - "minLength": 1 - }, - "type": { - "title": "Top level type", - "type": "string", - "const": "object" - }, - "$defs": { - "title": "Parameter groups", - "type": "object", - "patternProperties": { - "^.*$": { - "type": "object", - "required": [ - "title", - "type", - "properties" - ], - "properties": { - "title": { - "type": "string", - "minLength": 1 - }, - "type": { - "const": "object" - }, - "fa_icon": { - "type": "string", - "pattern": "^fa" - }, - "description": { - "type": "string" - }, - "required": { - "type": "array" - }, - "properties": { - "type": "object", - "patternProperties": { - "^.*$": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "type": { - "type": "string", - "enum": ["string", "boolean", "integer", "number"] - }, - "format": { - "type": "string", - "enum": ["file-path", "directory-path", "path", "file-path-pattern"] - }, - "exists": { - "type": "boolean" - }, - "mimetype": { - "type": "string", - "pattern": ".+/.+" - }, - "pattern": { - "type": "string", - "minLength": 1 - }, - "schema": { - "type": "string", - "minLength": 1 - }, - "description": { - "type": "string" - }, - "help_text": { - "type": "string" - }, - "fa_icon": { - "type": "string", - "pattern": "^fa" - }, - "errorMessage": { - "type": "string", - "minLength": 1 - }, - "hidden": { - "type": "boolean" - }, - "minLength": { - "type": "integer" - }, - "maxLength": { - "type": "integer" - }, - "minimum": { - "type": "integer" - }, - "maximum": { - "type": "integer" - } - } - } - } - } - } - } - } - }, - "allOf": { - "title": "Combine definition groups", - "type": "array", - "items": { - "type": "object", - "required": [ - "$ref" - ], - "properties": { - "$ref": { - "type": "string", - "pattern": "^#/$defs/" - } - } - } - } - }, - "required": [ - "$schema", - "$id", - "title", - "description", - "type" - ] -} diff --git a/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json b/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json index 09df35b..597f4d2 100644 --- a/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json +++ b/plugins/nf-schema/src/resources/schemas/parameters/1.0/parameters_meta_schema.json @@ -1 +1 @@ -{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://nextflow.io","title":"NextflowSchemaMeta-schema","description":"Meta-schematovalidateNextflowparameterschemafiles","type":"object","properties":{"$schema":{"title":"schema","type":"string","minLength":1},"$id":{"title":"IDURI","type":"string","minLength":1},"title":{"title":"Title","type":"string","minLength":1},"description":{"title":"Description","type":"string","minLength":1},"type":{"title":"Topleveltype","type":"string","const":"object"},"$defs":{"title":"Parametergroups","type":"object","patternProperties":{"^.*$":{"type":"object","required":["title","type","properties"],"properties":{"title":{"type":"string","minLength":1},"type":{"const":"object"},"fa_icon":{"type":"string","pattern":"^fa"},"description":{"type":"string"},"required":{"type":"array"},"properties":{"$ref":"#/$defs/parameterOptions"},"dependentRequired":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"},"uniqueItems":true,"default":[]}}}}}},"properties":{"$ref":"#/$defs/parameterOptions"},"dependentRequired":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"},"uniqueItems":true,"default":[]}},"allOf":{"title":"Combinedefinitiongroups","type":"array","items":{"type":"object","required":["$ref"],"properties":{"$ref":{"type":"string","pattern":"^#/\\$defs/[^/]+$"}}}}},"required":["$schema","$id","title","description","type"],"$defs":{"typeAnnotation":{"type":"string","enum":["string","boolean","integer","number","null"]},"allTypes":{"type":["integer","boolean","string","number","null"]},"nonNegativeInteger":{"type":"integer","minimum":0},"parameterOptions":{"type":"object","patternProperties":{"^.*$":{"type":"object","allOf":[{"$ref":"#/$defs/standardKeywords"},{"$ref":"#/$defs/customKeywords"}],"required":["type","description"],"unevaluatedProperties":false}}},"standardKeywords":{"type":"object","description":"AllowedstandardJSONSchemaproperties.","properties":{"type":{"description":"Thetypeoftheparametervalue.Canbeoneormoreofthese:`['integer','boolean','number','string','null']`","anyOf":[{"$ref":"#/$defs/typeAnnotation"},{"type":"array","items":{"$ref":"#/$defs/typeAnnotation"}}]},"format":{"type":"string","description":"Theformatofaparametervaluewiththe'string'type.Thisisusedforadditionalvalidationonthestructureofthevalue.","enum":["file-path","directory-path","path","file-path-pattern","date-time","date","time","email","uri","regex"]},"pattern":{"type":"string","format":"regex","minLength":1,"description":"Checkaparametervalueof'string'typeagainstaregexpattern"},"description":{"type":"string","description":"Thedescriptionofthecurrentparameter"},"default":{"$ref":"#/$defs/allTypes","description":"Specifiesadefaultvaluetouseforthisparameter"},"examples":{"type":"array","items":{"$ref":"#/$defs/allTypes"},"description":"Alistofexamplesforthecurrentparameter"},"deprecated":{"type":"boolean","description":"Statesthattheparameterisdeprecated.Pleaseprovideanicedeprecationmessageusing'errorMessage'"},"minLength":{"$ref":"#/$defs/nonNegativeInteger","description":"Theminimumlengtha'string'parametervalueshouldbe"},"maxLength":{"$ref":"#/$defs/nonNegativeInteger","description":"Themaximumlengtha'string'parametervalueshouldbe"},"minimum":{"type":"number","description":"Themimimumvaluean'integer'or'number'parametervalueshouldbe"},"exclusiveMinimum":{"type":"number","description":"Theexclusivemimimumvaluean'integer'or'number'parametervalueshouldbe"},"maximum":{"type":"number","description":"Themaximumvaluean'integer'or'number'parametervalueshouldbe"},"exclusiveMaximum":{"type":"number","description":"Theexclusivemaximumvaluean'integer'or'number'parametervalueshouldbe"},"multipleOf":{"type":"number","description":"The'integer'or'number'parametervalueshouldbeamultipleofthisvalue"},"enum":{"type":"array","uniqueItems":true,"items":{"$ref":"#/$defs/allTypes"},"description":"Theparametervalueshouldbeoneofthevaluesspecifiedinthisenumarray"},"const":{"$ref":"#/$defs/allTypes","description":"Theparametervalueshouldbeequaltothisvalue"}}},"customKeywords":{"type":"object","description":"AdditionalcustomJSONSchemaproperties.","properties":{"errorMessage":{"type":"string","minLength":1,"description":"NONSTANDARDOPTION:Thecustomerrormessagetodisplayincasevalidationagainstthisparameterfails.Canalsobeusedasadeprecationmessageif'deprecated'istrue"},"exists":{"type":"boolean","description":"NONSTANDARDOPTION:Checkifafileexists.Thisparametervalueneedstobea`string`typewithoneoftheseformats:`['path','file-path','directory-path','file-path-pattern']`"},"schema":{"type":"string","minLength":1,"pattern":"\\.json$","description":"NONSTANDARDOPTION:Checkthegivenfileagainstaschemapassedtothiskeyword.Willonlyworkwhentypeis`string`andformatis`path`or`file-path`"},"help_text":{"type":"string","description":"NONSTANDARDOPTION:Amoredetailedhelptext"},"fa_icon":{"type":"string","pattern":"^fa","description":"NONSTANDARDOPTION:Afontawesomeicontouseinthenf-coreparameterdocumentation"},"hidden":{"type":"boolean","description":"NONSTANDARDOPTION:Hidethisparameterfromthehelpmessageanddocumentation"},"mimetype":{"type":"string","description":"NONSTANDARDOPTION:TheMIMEtypeoftheparametervalue","deprecated":true,"errorMessage":"The'mimetype'keywordisdeprecated.Use'pattern'or'format'instead."}},"dependentSchemas":{"exists":{"$comment":"Thischecksifthetypeisa'string'andtheformatcorrespondstoafileordirectorywhen'exists'isused.","properties":{"type":{"const":"string"},"format":{"enum":["path","file-path","file-path-pattern","directory-path"]}}},"schema":{"$comment":"Thischecksifthetypeisa'string'andtheformatis'path'or'file-path'","properties":{"type":{"const":"string"},"format":{"enum":["path","file-path"]}}}}}}} \ No newline at end of file +{"$schema": "https://json-schema.org/draft/2020-12/schema","$id": "https://nextflow.io","title": "Nextflow Schema Meta-schema","description": "Meta-schema to validate Nextflow parameter schema files","type": "object","properties": {"$schema": {"title": "schema","type": "string","minLength": 1},"$id": {"title": "ID URI","type": "string","minLength": 1},"title": {"title": "Title","type": "string","minLength": 1},"description": {"title": "Description","type": "string","minLength": 1},"type": {"title": "Top level type","type": "string","const": "object"},"$defs": {"title": "Parameter groups","type": "object","patternProperties": {"^.*$": {"type": "object","required": ["title", "type", "properties"],"properties": {"title": {"type": "string","minLength": 1},"type": {"const": "object"},"fa_icon": {"type": "string","pattern": "^fa"},"description": {"type": "string"},"required": {"type": "array"},"properties": {"$ref": "#/$defs/parameterOptions"},"dependentRequired": {"type": "object","additionalProperties": {"type": "array","items": {"type": "string"},"uniqueItems": true,"default": []}}}}}},"properties": {"$ref": "#/$defs/parameterOptions"},"dependentRequired": {"type": "object","additionalProperties": {"type": "array","items": {"type": "string"},"uniqueItems": true,"default": []}},"allOf": {"title": "Combine definition groups","type": "array","items": {"type": "object","required": ["$ref"],"properties": {"$ref": {"type": "string","pattern": "^#/\\$defs/[^/]+$"}}}}},"required": ["$schema", "$id", "title", "description", "type"],"$defs": {"typeAnnotation": {"type": "string","enum": ["string", "boolean", "integer", "number", "null"]},"allTypes": {"type": ["integer", "boolean", "string", "number", "null"]},"nonNegativeInteger": {"type": "integer","minimum": 0},"parameterOptions": {"type": "object","patternProperties": {"^.*$": {"type": "object","allOf": [{ "$ref": "#/$defs/standardKeywords" },{ "$ref": "#/$defs/customKeywords" }],"required": ["type", "description"],"unevaluatedProperties": false}}},"standardKeywords": {"type": "object","description": "Allowed standard JSON Schema properties.","properties": {"type": {"description": "The type of the parameter value. Can be one or more of these: `['integer', 'boolean', 'number', 'string', 'null']`","anyOf": [{ "$ref": "#/$defs/typeAnnotation" },{"type": "array","items": { "$ref": "#/$defs/typeAnnotation" }}]},"format": {"type": "string","description": "The format of a parameter value with the 'string' type. This is used for additional validation on the structure of the value.","enum": ["file-path","directory-path","path","file-path-pattern","date-time","date","time","email","uri","regex"]},"pattern": {"type": "string","format": "regex","minLength": 1,"description": "Check a parameter value of 'string' type against a regex pattern"},"description": {"type": "string","description": "The description of the current parameter"},"default": {"$ref": "#/$defs/allTypes","description": "Specifies a default value to use for this parameter"},"examples": {"type": "array","items": {"$ref": "#/$defs/allTypes"},"description": "A list of examples for the current parameter"},"deprecated": {"type": "boolean","description": "States that the parameter is deprecated. Please provide a nice deprecation message using 'errorMessage'"},"minLength": {"$ref": "#/$defs/nonNegativeInteger","description": "The minimum length a 'string' parameter value should be"},"maxLength": {"$ref": "#/$defs/nonNegativeInteger","description": "The maximum length a 'string' parameter value should be"},"minimum": {"type": "number","description": "The mimimum value an 'integer' or 'number' parameter value should be"},"exclusiveMinimum": {"type": "number","description": "The exclusive mimimum value an 'integer' or 'number' parameter value should be"},"maximum": {"type": "number","description": "The maximum value an 'integer' or 'number' parameter value should be"},"exclusiveMaximum": {"type": "number","description": "The exclusive maximum value an 'integer' or 'number' parameter value should be"},"multipleOf": {"type": "number","description": "The 'integer' or 'number' parameter value should be a multiple of this value"},"enum": {"type": "array","uniqueItems": true,"items": {"$ref": "#/$defs/allTypes"},"description": "The parameter value should be one of the values specified in this enum array"},"const": {"$ref": "#/$defs/allTypes","description": "The parameter value should be equal to this value"}}},"customKeywords": {"type": "object","description": "Additional custom JSON Schema properties.","properties": {"errorMessage": {"type": "string","minLength": 1,"description": "NON STANDARD OPTION: The custom error message to display in case validation against this parameter fails. Can also be used as a deprecation message if 'deprecated' is true"},"exists": {"type": "boolean","description": "NON STANDARD OPTION: Check if a file exists. This parameter value needs to be a `string` type with one of these formats: `['path', 'file-path', 'directory-path', 'file-path-pattern']`"},"schema": {"type": "string","minLength": 1,"pattern": "\\.json$","description": "NON STANDARD OPTION: Check the given file against a schema passed to this keyword. Will only work when type is `string` and format is `path` or `file-path`"},"help_text": {"type": "string","description": "NON STANDARD OPTION: A more detailed help text"},"fa_icon": {"type": "string","pattern": "^fa","description": "NON STANDARD OPTION: A font awesome icon to use in the nf-core parameter documentation"},"hidden": {"type": "boolean","description": "NON STANDARD OPTION: Hide this parameter from the help message and documentation"},"mimetype": {"type": "string","description": "NON STANDARD OPTION: The MIME type of the parameter value","deprecated": true,"errorMessage": "The 'mimetype' keyword is deprecated. Use 'pattern' or 'format' instead."}},"dependentSchemas": {"exists": {"$comment": "This checks if the type is a 'string' and the format corresponds to a file or directory when 'exists' is used.","properties": {"type": { "const": "string" },"format": {"enum": ["path","file-path","file-path-pattern","directory-path"]}}},"schema": {"$comment": "This checks if the type is a 'string' and the format is 'path' or 'file-path'","properties": {"type": { "const": "string" },"format": {"enum": ["path", "file-path"]}}}}}}} \ No newline at end of file From 8b708cbb5e268d7091f925f258bdd92bff56af2d Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Wed, 19 Mar 2025 13:53:16 +0100 Subject: [PATCH 8/8] remove the validation mode --- CHANGELOG.md | 3 +- docs/configuration/configuration.md | 11 -- .../nextflow_schema_specification.md | 6 +- .../validation/config/ValidationConfig.groovy | 11 -- .../validators/JsonSchemaValidator.groovy | 10 +- .../validation/ValidateParametersTest.groovy | 106 ------------------ 6 files changed, 6 insertions(+), 141 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 213650d..156d944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,8 @@ ## New features -1. Added 2 new configuration options: +1. Added 1 new configuration option: - `validation.maxErrValSize` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. - - `validation.mode` which sets the validation mode. Possible options are `limited` and `unlimited`. In `limited` mode the JSON schemas for parameters will be limited to the official Nextflow specs to ensure compatibility with nf-core tooling, Seqera platform and other tools. These restrictions are not set when using `unlimited` mode. The default is set to `unlimited` to retain backwards compatibility. 2. Added a new function: `validate()` that can be used to validate any data structure using a JSON schema. 3. Add support for the official Nextflow JSON schema specification for parameters located in https://github.com/nextflow-io/schema-spec diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index c2bd459..2fa99b7 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -30,17 +30,6 @@ validation.parametersSchema = "path/to/schema.json" // default "nextflow_schema. This option can either be a path relative to the root of the pipeline directory or a full path to the JSON schema (Be wary to not use hardcoded local paths to ensure your pipeline will keep working on other systems) -## mode - -This option can be used to set the validation mode for parameters. There are two valid options: - -- `unlimited`: No restrictions apply on the validation of parameters. All keywords and schema structures available in [draft 2020-12](https://json-schema.org/draft/2020-12) can be used freely. -- `limited`: Limits the usage of keywords and schema structures for parameter validation to a subset of [draft 2020-12](https://json-schema.org/draft/2020-12). Enabling this mode will ensure compatibility with nf-core tooling, Seqera platform and others. The specified `$schema` inside of the parameters JSON schema needs to be set to the [official Nextflow meta schema](https://github.com/nextflow-io/schema-spec) for parameters. - -```groovy -validation.mode = "limited|unlimited" // default: "limited" -``` - ## monochromeLogs This option can be used to turn of the colored logs from nf-validation. This can be useful if you run a Nextflow pipeline in an environment that doesn't support colored logging. diff --git a/docs/nextflow_schema/nextflow_schema_specification.md b/docs/nextflow_schema/nextflow_schema_specification.md index d839e85..4529f2e 100644 --- a/docs/nextflow_schema/nextflow_schema_specification.md +++ b/docs/nextflow_schema/nextflow_schema_specification.md @@ -82,7 +82,7 @@ However, they will be displayed as ungrouped in tools working off the schema. ## Nested parameters -!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" +!!! example "Not supported in by the official [Nextflow specifications](https://github.com/nextflow-io/schema-spec/blob/main/parameters_meta_schema.json)" Nextflow config allows parameters to be nested as objects, for example: @@ -397,7 +397,7 @@ Example usage is as follows: ### `mimetype` -!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" +!!! example "Not supported in by the official [Nextflow specifications](https://github.com/nextflow-io/schema-spec/blob/main/parameters_meta_schema.json)" MIME type for a file path. Setting this value informs downstream tools about what _kind_ of file is expected. @@ -467,7 +467,7 @@ Specify a minimum / maximum value for an integer or float number length with `mi ## Array-specific keys -!!! example "Not supported in [limited](../configuration/configuration.md#mode) mode" +!!! example "Not supported in by the official [Nextflow specifications](https://github.com/nextflow-io/schema-spec/blob/main/parameters_meta_schema.json)" ### `uniqueItems` diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index c40d77f..7dc6b64 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -21,7 +21,6 @@ class ValidationConfig { final public String parametersSchema final public Boolean showHiddenParams final public Integer maxErrValSize = 150 - final public String mode = "unlimited" final public HelpConfig help final public SummaryConfig summary @@ -48,16 +47,6 @@ class ValidationConfig { help = new HelpConfig(config.help as Map ?: [:], params, monochromeLogs, showHiddenParams) summary = new SummaryConfig(config.summary as Map ?: [:], monochromeLogs) - if(config.containsKey("mode")) { - def List allowedModes = ["limited", "unlimited"] - if(allowedModes.contains(config.mode)) { - mode = config.mode - } else { - log.warn("Detected an unsupported mode in `validation.mode`, supported options are: ${allowedModes}, defaulting to `${mode}`") - } - log.debug("Set nf-schema validation mode to `${mode}`") - } - if(config.ignoreParams && !(config.ignoreParams instanceof List)) { throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values") } diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index 322b723..9420916 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -58,15 +58,9 @@ public class JsonSchemaValidator { def JSONObject schema = new JSONObject(schemaString) def String draft = getValueFromJsonPointer("#/\$schema", schema) def String draft2020_12 = "https://json-schema.org/draft/2020-12/schema" - if(config.mode == "limited" && validationType == "parameter" && !supportedCustomParameterDrafts.containsKey(draft)) { - log.error("""Failed to load meta schema: - Using '${draft}' for parameter JSON schemas is not allowed in limited mode. Please use one the following meta schemas instead: -${supportedCustomParameterDrafts.collect{ url, cachedSchema -> " - ${url}"}.join("\n") } - """) - throw new SchemaValidationException("", []) - } else if(draft != draft2020_12 && !supportedCustomParameterDrafts.containsKey(draft)) { + if(draft != draft2020_12 && !supportedCustomParameterDrafts.containsKey(draft)) { log.error("""Failed to load the meta schema: - The used schema draft (${draft}) is not correct, please use \"${draft2020_12}\" instead. + The used schema draft (${draft}) is not correct, please use \"${draft2020_12}\" or one of the other supported specifications instead. - If you are a pipeline developer, check our migration guide for more information: https://nextflow-io.github.io/nf-schema/latest/migration_guide/ - If you are a pipeline user, revert back to nf-validation to avoid this error: https://www.nextflow.io/docs/latest/plugins.html#using-plugins, i.e. set `plugins { id 'nf-validation@1.1.3' diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index 36742a4..513c60c 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1435,110 +1435,4 @@ class ValidateParametersTest extends Dsl2Spec{ error.message.contains("* --input (src/testRe..._extension): \"src/testResources/wrong_samplesheet_with_a_super_long_name.and_a_weird_extension\" does not match regular expression [^\\S+\\.(csv|tsv|yaml|json)\$]") !stdout } - - def 'should fail with draft 2020_12 in limited mode' () { - given: - def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() - def SCRIPT = """ - include { validateParameters } from 'plugin/nf-schema' - - validateParameters(parameters_schema: '$schema') - """ - - when: - def config = ["validation": [ - "mode": "limited" - ]] - def result = new MockScriptRunner(config).setScript(SCRIPT).execute() - def stdout = capture - .toString() - .readLines() - .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } - - then: - def error = thrown(SchemaValidationException) - !stdout - } - - def 'should validate with custom parameter meta schema in limited mode' () { - given: - def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() - def SCRIPT = """ - params.input = 'src/testResources/correct.csv' - params.outdir = 'src/testResources/testDir' - include { validateParameters } from 'plugin/nf-schema' - - validateParameters(parameters_schema: '$schema') - """ - - when: - def config = ["validation": [ - "mode": "limited" - ]] - def result = new MockScriptRunner(config).setScript(SCRIPT).execute() - def stdout = capture - .toString() - .readLines() - .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } - - then: - noExceptionThrown() - !stdout - } - - def 'should validate with custom parameter meta schema in unlimited mode' () { - given: - def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() - def SCRIPT = """ - params.input = 'src/testResources/correct.csv' - params.outdir = 'src/testResources/testDir' - include { validateParameters } from 'plugin/nf-schema' - - validateParameters(parameters_schema: '$schema') - """ - - when: - def config = ["validation": [ - "mode": "unlimited" - ]] - def result = new MockScriptRunner(config).setScript(SCRIPT).execute() - def stdout = capture - .toString() - .readLines() - .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } - - then: - noExceptionThrown() - !stdout - } - - def 'should validate with custom parameter meta schema in limited mode - failure' () { - given: - def schema = Path.of('src/testResources/nextflow_schema_custom_param_meta_schema.json').toAbsolutePath().toString() - def SCRIPT = """ - include { validateParameters } from 'plugin/nf-schema' - - validateParameters(parameters_schema: '$schema') - """ - - when: - def config = ["validation": [ - "mode": "limited", - "monochromeLogs": true - ]] - def result = new MockScriptRunner(config).setScript(SCRIPT).execute() - def stdout = capture - .toString() - .readLines() - .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } - - then: - def error = thrown(SchemaValidationException) - error.message == """The following invalid input values have been detected: - -* Missing required parameter(s): input, outdir - -""" - !stdout - } } \ No newline at end of file