Skip to content
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

Urgent help with populating an enum/oneOf with the key values of an array/object map #4099

Open
1 task done
devriaanvanniekerk opened this issue Feb 22, 2024 · 4 comments

Comments

@devriaanvanniekerk
Copy link

Prerequisites

What theme are you using?

other

What is your question?

Hi All,

I've been on a journey with rjsf for about a week now and let me start with a complement to the chefs! I need to render administrator forms that adhere to unseen schemas provided by means of dropped files - so no prior knowledge 😅. This project has been instrumental in getting there - many, many thanks!

I'll drop my schema down below, but in short for my config a user can define a network in an object map with the network name as key. In one of another subsequent objects fields the user should be able to select a network name. So given the filled in config below:
net_defs

Something like this should be presented:
net_select

I've had to write my own templates, widgets and fields in javascript using the Wildfly component library (requirements 🤷), however it all follows the typescript logic and changes were essentially only visual with the exception of one or two provisions needing to be made for the Wildfly components. Though I've written the odd SPA I am a backed developer turned systems engineer, so I've hit a bit of an ability wall... If anyone could provide me with direction/inspiration I'd be indebted 🙏

schema

Monolithic Schema

Still slugging it out as I go along, but current in it's form:

{
    "$id": "http://example.com/schemas/pvs_config.schema",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "PVS Configuration",
    "description": "Provisioning Server Configuration",
    "type": "object",
    "properties": {
        "SiteNotworks": { <===
            "type": "object",
            "additionalProperties": {
                "type": "object",
                "properties": {
                    "CIDR": {
                        "type": "string"
                    },
                    "Description": {
                        "type": "string"
                    },
                    "Zone": {
                        "type": "string"
                    }
                },
                "required": ["CIDR", "Zone"]
            },
            "default": {
                "external": {
                    "CIDR": "172.16.0.0/16",
                    "Description": "External network",
                    "Zone": "external"
                },
                "provisioning": {
                    "CIDR": "192.168.0.0/16",
                    "Description": "Provisioning network",
                    "Zone": "trusted"
                }
            }
        },
        "PVSConfig": {
            "type": "object",
            "properties": {
                "Domain": {
                    "type": "string"
                },
                "AdminPassword": {
                    "type": "string"
                },
                "Gateway": {
                    "type": "string"
                },
                "ExternalNetwork": {
                    ??? <===
                },
                "NTPSources": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "examples": ["172.16.63.17"]
                    },
                    "default": ["172.16.63.17"]
                },
                "RemoteHosts": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Hostname": {
                                "type": "string"
                            },
                            "IPv4Address": {
                                "type": "string"
                            }
                        },
                        "required": ["Hostname", "IPv4Address"]
                    }
                },
                "NetworkInterfaces": {
                    "type": "object",
                    "additionalProperties": {
                        "type": "object",
                        "properties": {
                            "Enabled": {
                                "type": "boolean",
                                "description": "Whether the interface should be enabled",
                                "default": false
                            },
                            "Type": {
                                "enum": ["Ethernet", "Bridge"],
                                "default": "Ethernet"
                            },
                            "DHCPConfigured": {
                                "type": "boolean",
                                "description": "Whether to use a DHCP assigned IP, will use static IP if false",
                                "default": false
                            },
                            "MTU": {
                                "type": "integer",
                                "description": "Maximum Transmission Unit, typical values are 1500 for Ethernet and 2044 for Infiniband",
                                "default": 1500,
                                "minimum": 0
                            },
                            "MAC": {
                                "type": "string"
                            },
                            "IPAddresses": {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            }
                        },
                        "required": ["MAC", "IPAddresses"]
                    }
                },
                "StaticRoutes": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "CIDR": {
                                "type": "string"
                            },
                            "GatewayIPv4Address": {
                                "type": "string"
                            }
                        },
                        "required": ["Hostname", "IPv4Address"]
                    }
                },
                "DNSForwarders": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "Journald": {
                    "type": "object",
                    "properties": {
                        "PersistToDisk": {
                            "type": "boolean",
                            "description": "Persist to disk rather than RAM",
                            "default": true
                        },
                        "MaxSize": {
                            "type": "string",
                            "description": "The maximum size the journal may consume, eg. 4G. 'K', 'M' and 'G' suffixes are allowed. If omitted wil default to 10% (disk) or 15% (RAM).",
                            "pattern": "^[0-9]+[KMG]$",
                            "default": "4G"
                        }
                    }
                },
                "Repositories": {
                    "type": "array",
                    "description": "Repositories that should be made available to the Host",
                    "items": {
                        "type": "string"
                    }
                },
                "KernelBootParameters": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": ["Domain", "AdminPassword", "ExternalNetwork"]
        },
        "SiteProvisioning": {
            "type": "object",
            "properties": {
                "Enabled": {
                    "type": "boolean",
                    "description": "Whether the Podman Container Runtime should be enabled",
                    "default": false
                },
                "ProvisioningUnits": {
                    "type":"object",
                    "additionalProperties": {
                        "type": "object",
                        "properties": {
                            "ExternalNetwork": {
                                "type": "string"
                            },
                            "ProvisioningNetwork": {
                                "type": "string"
                            },
                            "Repositories": {
                                "type": "array",
                                "description": "Repositories that should be made available to the Host",
                                "items": {
                                    "type": "string"
                                }
                            },
                            "StaticRoutes": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "CIDR": {
                                            "type": "string"
                                        },
                                        "GatewayIPv4Address": {
                                            "type": "string"
                                        }
                                    },
                                    "required": ["Hostname", "IPv4Address"]
                                }
                            },
                            "KernelBootParameters": {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            },
                            "Containerization": {
                                "description": "Container runtime and image registry configuration",
                                "type": "object",
                                "properties": {
                                    "Enabled": {
                                        "type": "boolean",
                                        "description": "Whether the Podman Container Runtime should be enabled",
                                        "default": false
                                    },
                                    "ExternalRegistries": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "Host": {
                                                    "type": "string",
                                                    "pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$"
                                                },
                                                "Port": {
                                                    "type": "integer",
                                                    "minimum": 1,
                                                    "default": 5000
                                                }
                                            },
                                            "required": ["Host", "Port"],
                                            "additionalProperties": false
                                        },
                                        "description": "The image registries for Podman to reference when pulling images (FQDN and Port)"
                                    },
                                    "HostedRegistry": {
                                        "type": "object",
                                        "properties": {
                                            "Enabled": {
                                                "type": "boolean",
                                                "description": "Whether to deploy a hosted image registry",
                                                "default": false
                                            },
                                            "BindMount": {
                                                "type": "string",
                                                "description": "The remote path to bind the registry storage to",
                                                "pattern": "^\/(?:[^\/]+\/?)*$",
                                                "default": "/var/registry/"
                                            },
                                            "RegistryPort": {
                                                "type": "integer",
                                                "description": "The registry TCP port",
                                                "minimum": 1024,
                                                "default": 5000
                                            }
                                        },
                                        "description": "Configuration relating to a self-hosted Image Registry"
                                    }
                                }
                            },
                            "Master": {
                                "type": "object",
                                "properties": {
                                    "SerialNumber": {
                                        "type": "string"
                                    },
                                    "ProductName": {
                                        "type": "string"
                                    },
                                    "MinifiedHostname": {
                                        "type": "string"
                                    },
                                    "RootDevice": {
                                        "type": "string"
                                    },
                                    "RootPartitionSizeMB": {
                                        "type": "integer"
                                    },
                                    "LogPartitionSizeMB": {
                                        "type": "integer"
                                    },
                                    "NetworkInterfaces": {
                                        "type": "object",
                                        "additionalProperties": {
                                            "type": "object",
                                            "properties": {
                                                "CIDR": {
                                                    "type": "string"
                                                },
                                                "Description": {
                                                    "type": "string"
                                                },
                                                "Zone": {
                                                    "type": "string"
                                                }
                                            },
                                            "required": ["CIDR", "Zone"]
                                        }
                                    },
                                    "StaticRoutes": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "CIDR": {
                                                    "type": "string"
                                                },
                                                "GatewayIPv4Address": {
                                                    "type": "string"
                                                }
                                            },
                                            "required": ["Hostname", "IPv4Address"]
                                        }
                                    },
                                    "KernelBootParameters": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    },
                                    "Journald": {
                                        "type": "object",
                                        "properties": {
                                            "PersistToDisk": {
                                                "type": "boolean",
                                                "description": "Persist to disk rather than RAM",
                                                "default": true
                                            },
                                            "MaxSize": {
                                                "type": "string",
                                                "description": "The maximum size the journal may consume, eg. 4G. 'K', 'M' and 'G' suffixes are allowed. If omitted wil default to 10% (disk) or 15% (RAM).",
                                                "pattern": "^[0-9]+[KMG]$",
                                                "default": "4G"
                                            }
                                        }
                                    },
                                    "WeeklyBackup": {
                                        "type": "object",
                                        "properties": {
                                            "Enabled": {
                                                "type": "boolean",
                                                "default": false
                                            },
                                            "TargetHost": {
                                                "type": "string"
                                            },
                                            "TargetPath": {
                                                "type": "string",
                                                "pattern": "^\/(?:[^\/]+\/?)*$"
                                            },
                                            "RetentionDays": {
                                                "type": "integer",
                                                "default": 21
                                            }
                                        },
                                        "dependentRequired": {
                                            "Enabled": ["TargetHost", "Target", "RetentionDays"]
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "dependentRequired": {
                "Enabled": ["ProvisioningUnits"]
            }
        }
    }
}
@devriaanvanniekerk devriaanvanniekerk added needs triage Initial label given, to be assigned correct labels and assigned question labels Feb 22, 2024
@devriaanvanniekerk devriaanvanniekerk changed the title Urgent help with populating an enum/onOf with the key values of an array/object map Urgent help with populating an enum/oneOf with the key values of an array/object map Feb 22, 2024
@devriaanvanniekerk
Copy link
Author

UPDATE

I'm going to give a custom widget a go today, timelines are tight - any & all input still appriciated

@heath-freenome
Copy link
Member

Have you looked at the playground at the One Of example?

@heath-freenome heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Feb 23, 2024
@devriaanvanniekerk
Copy link
Author

Have you looked at the playground at the One Of example?

@heath-freenome, I did yeah, but it's another case of having the selection info at hand - I need to have a user on the form create a map of objects in one field and then select between their keys in another field.

I haven't come across an example of that yet if you can think of one?

@heath-freenome
Copy link
Member

@devriaanvanniekerk I'm not certain, but I believe that what you are attempting isn't even technically supported by the JSON Schema specification. You may have to write your own custom field to do something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants