-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add support for 'then/else' paths #1909
Changes from 4 commits
4fd6fc8
6706e50
33eb959
7ce3e05
eda008a
7d543eb
85a8fbc
8dd4852
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,13 +134,29 @@ export const resolveSchema = ( | |
const schemas = [].concat( | ||
resultSchema?.oneOf ?? [], | ||
resultSchema?.allOf ?? [], | ||
resultSchema?.anyOf ?? [] | ||
resultSchema?.anyOf ?? [], | ||
// also add root level schema composition entries | ||
schema?.oneOf ?? [], | ||
schema?.allOf ?? [], | ||
schema?.anyOf ?? [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the use cases where this is necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to explain this in english. I hope it is comprehensible. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels weird to me that we single out the case that the |
||
); | ||
for (let item of schemas) { | ||
for (const item of schemas) { | ||
curSchema = resolveSchema(item, validPathSegments.slice(i).map(encode).join('/')); | ||
if (curSchema) { | ||
break; | ||
} | ||
if (!curSchema) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition must be true, otherwise we would not be executed. see the |
||
const conditionalSchemas = [].concat( | ||
item.then ?? [], | ||
item.else ?? [], | ||
); | ||
for (const condiItem of conditionalSchemas) { | ||
curSchema = resolveSchema(condiItem, schemaPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By handing over the whole |
||
if (curSchema) { | ||
break; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only works if the |
||
} | ||
} | ||
if (curSchema) { | ||
// already resolved rest of the path | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
The MIT License | ||
|
||
Copyright (c) 2017-2019 EclipseSource Munich | ||
https://github.com/eclipsesource/jsonforms | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
import { registerExamples } from '../register'; | ||
|
||
export const schema = { | ||
type: 'object', | ||
properties: { | ||
name: { | ||
type: 'string', | ||
minLength: 1, | ||
description: 'The task\'s name', | ||
}, | ||
recurrence: { | ||
type: 'string', | ||
enum: ['Never', 'Daily', 'Weekly', 'Monthly'], | ||
}, | ||
}, | ||
anyOf: [ | ||
{ | ||
if: { | ||
properties: { | ||
recurrence: { | ||
const: 'Never' | ||
} | ||
} | ||
}, | ||
then: { | ||
properties: { | ||
lastname: { | ||
type: 'string' | ||
}, | ||
age: { | ||
type: 'number' | ||
} | ||
} | ||
} | ||
}, | ||
] | ||
}; | ||
|
||
export const uischema = { | ||
type: 'HorizontalLayout', | ||
elements: [ | ||
{ | ||
type: 'VerticalLayout', | ||
elements: [ | ||
{ | ||
type: 'Control', | ||
scope: '#/properties/name', | ||
}, | ||
{ | ||
type: 'Control', | ||
scope: '#/properties/recurrence', | ||
}, | ||
{ | ||
type: 'Control', | ||
scope: '#/anyOf/0/then/properties/lastname', | ||
rule: { | ||
effect: 'SHOW', | ||
condition: { | ||
scope: '#/properties/recurrence', | ||
schema: { | ||
const: 'Never' | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
type: 'Control', | ||
scope: '#/properties/age', | ||
rule: { | ||
effect: 'SHOW', | ||
condition: { | ||
scope: '#/properties/recurrence', | ||
schema: { | ||
const: 'Never' | ||
} | ||
} | ||
} | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const data = {}; | ||
|
||
registerExamples([ | ||
{ | ||
name: 'conditional-schema-compositions', | ||
label: 'Conditional Schema Compositions', | ||
data, | ||
schema, | ||
uischema | ||
} | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this just be another line? e.g.
.replace(/(then|else)\//g, '')
?I don't see why we should restrict ourselves purely to the case that the
then
orelse
is within a combinator. We also want to remove them when they are outside of them.Actually we could then just simplify to this, right?