Skip to content

Commit

Permalink
Include top-level properties in parameter schema
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman committed Dec 12, 2024
1 parent 18b5c58 commit 3c3f83d
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import groovy.json.JsonSlurper;
import nextflow.script.ast.ScriptNode;
Expand Down Expand Up @@ -97,8 +98,8 @@ private void declareParameters() {
return;
var schemaJson = getParameterSchema(schemaPath);

var defs = Optional.ofNullable(schemaJson)
.flatMap(json -> asMap(json))
var schema = asMap(schemaJson).orElse(Collections.emptyMap());
var defs = Optional.of(schema)
.flatMap(json ->
json.containsKey("$defs")
? asMap(json.get("$defs")) :
Expand All @@ -110,11 +111,17 @@ private void declareParameters() {
)
.orElse(Collections.emptyMap());

var entries = (List<Map.Entry>) defs.values().stream()
.filter(defn -> defn instanceof Map)
.map(defn -> ((Map) defn).get("properties"))
.filter(props -> props instanceof Map)
.flatMap(props -> ((Map) props).entrySet().stream())
var entries = (List<Map.Entry>) Stream.concat(Stream.of(schema), defs.values().stream())
.flatMap(defn ->
defn instanceof Map map
? Stream.of(map.get("properties"))
: Stream.empty()
)
.flatMap(props ->
props instanceof Map map
? map.entrySet().stream()
: Stream.empty()
)
.collect(Collectors.toList());

if( entries.isEmpty() )
Expand Down

0 comments on commit 3c3f83d

Please sign in to comment.