mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-23 22:46:53 +00:00
Fix: fix definition schema struct (#2632)
* Fix: fix definition schema struct * add more fields
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||
@@ -417,16 +418,30 @@ type DetailDefinitionResponse struct {
|
||||
}
|
||||
|
||||
type DefinitionSchema struct {
|
||||
Properties map[string]DefinitionProperties `json:"properties"`
|
||||
Required []string `json:"required"`
|
||||
Type string `json:"type"`
|
||||
Properties map[string]*DefinitionProperties `json:"properties"`
|
||||
Required []string `json:"required"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type DefinitionProperties struct {
|
||||
Default string `json:"default"`
|
||||
Description string `json:"description"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Items *DefinitionSchema `json:"items,omitempty"`
|
||||
Enum []interface{} `json:"enum,omitempty"`
|
||||
Default interface{} `json:"default,omitempty"`
|
||||
Example interface{} `json:"example,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
|
||||
// Number
|
||||
Min *float64 `json:"minimum,omitempty"`
|
||||
Max *float64 `json:"maximum,omitempty"`
|
||||
MultipleOf *float64 `json:"multipleOf,omitempty"`
|
||||
|
||||
// String
|
||||
MinLength uint64 `json:"minLength,omitempty"`
|
||||
MaxLength *uint64 `json:"maxLength,omitempty"`
|
||||
Pattern string `json:"pattern,omitempty"`
|
||||
compiledPattern *regexp.Regexp
|
||||
}
|
||||
|
||||
// DefinitionBase is the definition base model
|
||||
|
||||
@@ -98,29 +98,48 @@ var _ = Describe("Test namespace usecase functions", func() {
|
||||
Namespace: "vela-system",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"openapi-v3-json-schema": `{"properties":{"cluster":{"default":"","description":"Specify the cluster of the object","title":"cluster","type":"string"},"value":{"description":"Specify the value of the object","title":"value","type":"object"}},"required":["value","cluster"],"type":"object"}`,
|
||||
"openapi-v3-json-schema": `{"properties":{"batchPartition":{"title":"batchPartition","type":"integer"},"volumes": {"description":"Specify volume type, options: pvc, configMap, secret, emptyDir","enum":["pvc","configMap","secret","emptyDir"],"title":"volumes","type":"string"}, "rolloutBatches":{"items":{"properties":{"replicas":{"title":"replicas","type":"integer"}},"required":["replicas"],"type":"object"},"title":"rolloutBatches","type":"array"},"targetRevision":{"title":"targetRevision","type":"string"},"targetSize":{"title":"targetSize","type":"integer"}},"required":["targetRevision","targetSize"],"type":"object"}`,
|
||||
},
|
||||
}
|
||||
err := k8sClient.Create(context.Background(), cm)
|
||||
Expect(err).Should(Succeed())
|
||||
schema, err := definitionUsecase.DetailDefinition(context.TODO(), "apply-object", "workflowstep")
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(schema.Schema).Should(Equal(&v1.DefinitionSchema{
|
||||
Properties: map[string]v1.DefinitionProperties{
|
||||
"value": {
|
||||
Default: "",
|
||||
Description: "Specify the value of the object",
|
||||
Title: "value",
|
||||
Type: "object",
|
||||
},
|
||||
"cluster": {
|
||||
Default: "",
|
||||
Description: "Specify the cluster of the object",
|
||||
Title: "cluster",
|
||||
Properties: map[string]*v1.DefinitionProperties{
|
||||
"volumes": {
|
||||
Title: "volumes",
|
||||
Type: "string",
|
||||
Description: "Specify volume type, options: pvc, configMap, secret, emptyDir",
|
||||
Enum: []interface{}{"pvc", "configMap", "secret", "emptyDir"},
|
||||
},
|
||||
"batchPartition": {
|
||||
Title: "batchPartition",
|
||||
Type: "integer",
|
||||
},
|
||||
"rolloutBatches": {
|
||||
Items: &v1.DefinitionSchema{
|
||||
Properties: map[string]*v1.DefinitionProperties{
|
||||
"replicas": {
|
||||
Title: "replicas",
|
||||
Type: "integer",
|
||||
},
|
||||
},
|
||||
Required: []string{"replicas"},
|
||||
Type: "object",
|
||||
},
|
||||
Title: "rolloutBatches",
|
||||
Type: "array",
|
||||
},
|
||||
"targetSize": {
|
||||
Title: "targetSize",
|
||||
Type: "integer",
|
||||
},
|
||||
"targetRevision": {
|
||||
Title: "targetRevision",
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
Required: []string{"value", "cluster"},
|
||||
Required: []string{"targetRevision", "targetSize"},
|
||||
Type: "object",
|
||||
}))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user