diff --git a/CHANGELOG.md b/CHANGELOG.md index d006e47..0fd3b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.2.1] - 2021-08-02 + +### Fixed + +- Always allow empty process graphs if option is set + ## [1.2.0] - 2021-07-05 ### Added @@ -31,7 +37,8 @@ First stable release supporting openEO API 1.0.0. All prior releases have been documented in the [GitHub Releases](https://github.com/Open-EO/openeo-js-processgraphs/releases). -[Unreleased]: +[Unreleased]: +[1.2.1]: [1.2.0]: [1.1.0]: [1.0.0]: diff --git a/README.md b/README.md index 61f4b2e..f68484c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/Open-EO/openeo-js-processgraphs.svg?branch=master)](https://travis-ci.org/Open-EO/openeo-js-processgraphs) -This library's version is **1.2.0** and supports **openEO API version 1.x**. +This library's version is **1.2.1** and supports **openEO API version 1.x**. This repository was split apart from [openeo-js-commons](https://github.com/Open-EO/openeo-js-commons). Old releases can be found there. @@ -27,4 +27,4 @@ In a web environment you can include the library as follows: ``` -More information can be found in the [**documentation**](https://open-eo.github.io/openeo-js-processgraphs/1.2.0/). \ No newline at end of file +More information can be found in the [**documentation**](https://open-eo.github.io/openeo-js-processgraphs/1.2.1/). \ No newline at end of file diff --git a/package.json b/package.json index 837b6ad..576e61a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openeo/js-processgraphs", - "version": "1.2.0", + "version": "1.2.1", "author": "openEO Consortium", "contributors": [ { diff --git a/src/processgraph.js b/src/processgraph.js index 435730b..9b56bb2 100644 --- a/src/processgraph.js +++ b/src/processgraph.js @@ -5,6 +5,21 @@ const ProcessGraphNode = require('./node'); const Utils = require('./utils'); const ProcessUtils = require('@openeo/js-commons/src/processUtils.js'); +const processKeys = [ + 'id', + 'summary', + 'description', + 'categories', + 'parameters', + 'returns', + 'deprecated', + 'experimental', + 'exceptions', + 'examples', + 'links', + 'process_graph' +]; + /** * Process parser, validator and executor. * @@ -150,13 +165,14 @@ class ProcessGraph { } if (Utils.size(this.process.process_graph) === 0) { - if (this.allowEmptyGraph && Utils.size(this.process) === 0) { - this.parsed = true; - return; - } - else { - throw makeError('ProcessGraphMissing'); + if (this.allowEmptyGraph) { + let hasProcessKey = Object.keys(this.process).find(key => processKeys.includes(key)); + if (Utils.size(this.process) === 0 || hasProcessKey) { + this.parsed = true; + return; + } } + throw makeError('ProcessGraphMissing'); } this.nodes = Utils.mapObjectValues(this.process.process_graph, (pg, id) => this.createNodeInstance(pg, id, this)); diff --git a/tests/processgraph.test.js b/tests/processgraph.test.js index ed6003b..ecccc10 100644 --- a/tests/processgraph.test.js +++ b/tests/processgraph.test.js @@ -72,13 +72,13 @@ describe('Process Graph Tests', () => { expect(() => pg.parse()).toThrow(); }); - test('Parser > Empty process allowed', async () => { + test('Parser > allowEmpty > Empty process allowed', async () => { var pg = new ProcessGraph({}, registry); pg.allowEmpty(); expect(() => pg.parse()).not.toThrow(); }); - test('Parser > Fail on non-empty invalid processes', async () => { + test('Parser > allowEmpty > Fail on non-empty invalid processes', async () => { var pg = new ProcessGraph({"1": {process_id: "foo", arguments: {}}}, registry); pg.allowEmpty(); expect(() => pg.parse()).toThrow(); @@ -94,6 +94,12 @@ describe('Process Graph Tests', () => { expect(() => pg.parse()).toThrow(); }); + test('Parser > allowEmpty > Empty process graph does not throw', async () => { + var pg = new ProcessGraph({process_graph: {}}, registry); + pg.allowEmpty(); + expect(() => pg.parse()).not.toThrow(); + }); + test('Parser > Multiple result nodes throw', async () => { let absNode = { process_id: "absolute",