Add support for oneOf and allOf

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-04-29 10:36:53 +02:00
parent 23769512a3
commit 08e32cf913
3 changed files with 116 additions and 2 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/plugin-scaffolder': patch
---
Support anyOf schemas in the scaffolder template
Support `anyOf`, `oneOf` and `allOf` schemas in the scaffolder template.
@@ -94,6 +94,28 @@ describe('transformSchemaToProps', () => {
},
},
],
oneOf: [
{
properties: {
field4: {
type: 'string',
default: 'Value 1',
'ui:readonly': true,
},
},
},
],
allOf: [
{
properties: {
field5: {
type: 'string',
default: 'Value 1',
'ui:readonly': true,
},
},
},
],
properties: {
field1: {
type: 'object',
@@ -117,6 +139,28 @@ describe('transformSchemaToProps', () => {
},
},
],
oneOf: [
{
properties: {
field4: {
type: 'string',
default: 'Value 1',
'ui:readonly': true,
},
},
},
],
allOf: [
{
properties: {
field5: {
type: 'string',
default: 'Value 1',
'ui:readonly': true,
},
},
},
],
},
field2: {
type: 'string',
@@ -144,6 +188,26 @@ describe('transformSchemaToProps', () => {
},
},
],
oneOf: [
{
properties: {
field4: {
type: 'string',
default: 'Value 1',
},
},
},
],
allOf: [
{
properties: {
field5: {
type: 'string',
default: 'Value 1',
},
},
},
],
properties: {
field1: {
type: 'object',
@@ -165,6 +229,26 @@ describe('transformSchemaToProps', () => {
},
},
],
oneOf: [
{
properties: {
field4: {
type: 'string',
default: 'Value 1',
},
},
},
],
allOf: [
{
properties: {
field5: {
type: 'string',
default: 'Value 1',
},
},
},
],
},
field2: {
type: 'string',
@@ -175,10 +259,22 @@ describe('transformSchemaToProps', () => {
field3: {
'ui:readonly': true,
},
field4: {
'ui:readonly': true,
},
field5: {
'ui:readonly': true,
},
field1: {
field3: {
'ui:readonly': true,
},
field4: {
'ui:readonly': true,
},
field5: {
'ui:readonly': true,
},
},
field2: {
'ui:derp': 'xerp',
@@ -26,7 +26,7 @@ function extractUiSchema(schema: JsonObject, uiSchema: JsonObject) {
return;
}
const { properties, anyOf } = schema;
const { properties, anyOf, oneOf, allOf } = schema;
for (const propName in schema) {
if (!schema.hasOwnProperty(propName)) {
@@ -63,6 +63,24 @@ function extractUiSchema(schema: JsonObject, uiSchema: JsonObject) {
extractUiSchema(schemaNode, uiSchema);
}
}
if (Array.isArray(oneOf)) {
for (const schemaNode of oneOf) {
if (!isObject(schemaNode)) {
continue;
}
extractUiSchema(schemaNode, uiSchema);
}
}
if (Array.isArray(allOf)) {
for (const schemaNode of allOf) {
if (!isObject(schemaNode)) {
continue;
}
extractUiSchema(schemaNode, uiSchema);
}
}
}
export function transformSchemaToProps(