Feat(schema): parameter and output schemas from one model, with +ui markers (3/21)
Stack 3/21 · after #7422 · next #7396 (4/21, forEach) · VelaUX kubevela/velaux#959, kubevela/velaux#967 and kubevela/velaux#971 build on this
Description of your changes
Schema generation now works from one model of the template, pruned to parameter, and produces both the OpenAPI schema and a default UI schema, stored side by side in the definition's ConfigMaps.
+ui: markers shape the generated form:
parameter: {
// +ui:section=Networking
port: *80 | int
// +ui:optionsFrom=configs:image-registry
registry?: string
// +ui:expression=never
image: string
// +ui:error=Lowercase letters and digits only
name: =~"^[a-z0-9]+$"
}
Conditions (if parameter.x != _|_ { ... }) are followed across nested structs, lists and presence, so a field shows only when it applies. Addon parameter forms are generated the same way, and an invalid addon parameter is refused.
Output schemas. The schema of a template's output and outputs is generated and stored too (with status as any), including for a definition that extends another. That's what lets a tool type a read like $(component.db.output.data.host). SourceDefinitions store their parameter and schema the same way.
Hyphenated component names. CEL reads component.my-db as a subtraction, and the error was undeclared reference to 'db'. It now says to write component["my-db"], which works since the component root is a map.
Fixes #
I have:
- Read and followed KubeVela's pull request process.
- All commits are signed off (DCO).
- Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
- Run
make reviewableto ensure this PR is ready for review. - Added
backport release-x.ylabels to auto-backport this PR if necessary.
How has this code been tested
pkg/schema: the model, conditions,+uimarkers, pruning, output schemas and extends.pkg/addon,pkg/utilsand the SourceDefinition controller: what is stored.make lintandmake staticcheckclean.- On a k3d cluster running this stack's controller:
component-schema-webserviceholdsdefault-ui-schema,output-schemaandoutputs-schemabesideopenapi-v3-json-schema, and a SourceDefinition's ConfigMap holds itssource-output-schema.
Special notes for your reviewer
- This is the biggest of the KubeVela changes (about 5k lines, mostly
pkg/schemaand its tests). Happy to split the output schemas into their own PR if that's easier to review. - The stored UI schema is additive: anything reading only the OpenAPI schema is unaffected.