diff --git a/docs/release_notes/v0.3.3.md b/docs/release_notes/v0.3.3.md new file mode 100644 index 0000000..3c9c179 --- /dev/null +++ b/docs/release_notes/v0.3.3.md @@ -0,0 +1,3 @@ +# v0.3.3 Release + +- Add using `example`s if defined after `default` value in the schema. (#56) diff --git a/pkg/generate.go b/pkg/generate.go index a1cf675..fa904da 100644 --- a/pkg/generate.go +++ b/pkg/generate.go @@ -127,6 +127,10 @@ func outputValueType(v v1beta1.JSONSchemaProps) string { return string(v.Default.Raw) } + if v.Example != nil { + return string(v.Example.Raw) + } + st := "string" switch v.Type { case st: diff --git a/pkg/generate_test.go b/pkg/generate_test.go index bc22aad..d946f58 100644 --- a/pkg/generate_test.go +++ b/pkg/generate_test.go @@ -30,3 +30,22 @@ func TestGenerate(t *testing.T) { assert.Equal(t, golden, buffer.Bytes()) } + +func TestGenerateWithExample(t *testing.T) { + content, err := os.ReadFile(filepath.Join("testdata", "sample_crd_with_example.yaml")) + require.NoError(t, err) + + crd := &v1beta1.CustomResourceDefinition{} + require.NoError(t, yaml.Unmarshal(content, crd)) + + var output []byte + buffer := bytes.NewBuffer(output) + + version := crd.Spec.Versions[0] + require.NoError(t, ParseProperties(crd.Spec.Group, version.Name, crd.Spec.Names.Kind, version.Schema.OpenAPIV3Schema.Properties, buffer, 0, false, false)) + + golden, err := os.ReadFile(filepath.Join("testdata", "sample_crd_with_example_golden.yaml")) + require.NoError(t, err) + + assert.Equal(t, golden, buffer.Bytes()) +} diff --git a/pkg/testdata/sample_crd_with_example.yaml b/pkg/testdata/sample_crd_with_example.yaml new file mode 100644 index 0000000..33603d1 --- /dev/null +++ b/pkg/testdata/sample_crd_with_example.yaml @@ -0,0 +1,91 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.9.2 + creationTimestamp: null + name: krokcommands.delivery.krok.app +spec: + group: delivery.krok.app + names: + kind: KrokCommand + listKind: KrokCommandList + plural: krokcommands + singular: krokcommand + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: KrokCommand is the Schema for the krokcommands API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: KrokCommandSpec defines the desired state of KrokCommand + properties: + commandHasOutputToWrite: + description: CommandHasOutputToWrite if defined, it signals the underlying + Job, to put its output into a generated and created secret. + type: boolean + dependencies: + description: Dependencies defines a list of command names that this + command depends on. + items: + type: string + type: array + enabled: + description: Enabled defines if this command can be executed or not. + type: boolean + complex: + type: object + example: {key: "value"} + image: + description: 'Image defines the image name and tag of the command + example: krok-hook/slack-notification:v0.0.1' + type: string + example: krok-hook/slack-notification:v0.0.1 + platforms: + description: Platforms holds all the platforms which this command + supports. + items: + type: string + type: array + readInputFromSecret: + description: ReadInputFromSecret if defined, the command will take + a list of key/value pairs in a secret and apply them as arguments + to the command. + properties: + name: + type: string + namespace: + type: string + required: + - name + - namespace + type: object + schedule: + description: 'Schedule of the command. example: 0 * * * * // follows + cron job syntax.' + type: string + required: + - image + type: object + status: + description: KrokCommandStatus defines the observed state of KrokCommand + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/pkg/testdata/sample_crd_with_example_golden.yaml b/pkg/testdata/sample_crd_with_example_golden.yaml new file mode 100644 index 0000000..751fe4e --- /dev/null +++ b/pkg/testdata/sample_crd_with_example_golden.yaml @@ -0,0 +1,15 @@ +apiVersion: delivery.krok.app/v1alpha1 +kind: KrokCommand +metadata: {} +spec: + commandHasOutputToWrite: true + complex: {"key":"value"} + dependencies: ["string"] + enabled: true + image: "krok-hook/slack-notification:v0.0.1" + platforms: ["string"] + readInputFromSecret: + name: string + namespace: string + schedule: string +status: {} diff --git a/wasm/app-worker.js b/wasm/app-worker.js index ca4de86..6672202 100644 --- a/wasm/app-worker.js +++ b/wasm/app-worker.js @@ -1,8 +1,8 @@ -const cacheName = "app-" + "88fd944df3b3589e7578486efd86022ea07b8649"; +const cacheName = "app-" + "f12aae0089af3c57e2d86eef472876387bf42dc1"; const resourcesToCache = ["/","/app.css","/app.js","/manifest.webmanifest","/wasm_exec.js","/web/app.wasm","/web/css/alert.css","/web/img/logo.png","https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js","https://cdn.jsdelivr.net/npm/halfmoon@2.0.1/css/halfmoon.min.css","https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js","https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css","https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css"]; self.addEventListener("install", (event) => { - console.log("installing app worker 88fd944df3b3589e7578486efd86022ea07b8649"); + console.log("installing app worker f12aae0089af3c57e2d86eef472876387bf42dc1"); event.waitUntil( caches @@ -28,7 +28,7 @@ self.addEventListener("activate", (event) => { ); }) ); - console.log("app worker 88fd944df3b3589e7578486efd86022ea07b8649 is activated"); + console.log("app worker f12aae0089af3c57e2d86eef472876387bf42dc1 is activated"); }); self.addEventListener("fetch", (event) => { diff --git a/wasm/app.go b/wasm/app.go index d58cb1b..8930212 100644 --- a/wasm/app.go +++ b/wasm/app.go @@ -191,14 +191,14 @@ func render(d app.UI, p []*Property, accordionID string, depth int) app.UI { ), ) - buttonID := "accordion-button-id-" + prop.Name + accordionID - button := app.Button().ID(buttonID).Class("accordion-button").Type("button").DataSets( + targetID := "accordion-collapse-for-" + prop.Name + accordionID + button := app.Button().ID("accordion-button-id-"+prop.Name+accordionID).Class("accordion-button").Type("button").DataSets( map[string]any{ "bs-toggle": "collapse", - "bs-target": buttonID, + "bs-target": "#" + targetID, // the # is important }). Aria("expanded", "false"). - Aria("controls", buttonID). + Aria("controls", targetID). Body( headerContainer, ) @@ -216,15 +216,14 @@ func render(d app.UI, p []*Property, accordionID string, depth int) app.UI { continue } - accordionDivID := "accordion-collapse-for-" + prop.Name + accordionID - accordionDiv := app.Div().Class("accordion-collapse collapse").ID(accordionDivID).DataSet("bs-parent", "#"+accordionID) + accordionDiv := app.Div().Class("accordion-collapse collapse").ID(targetID).DataSet("bs-parent", "#"+accordionID) accordionBody := app.Div().Class("accordion-body") var bodyElements []app.UI // add any children that the parent has if len(prop.Properties) > 0 { - element := render(app.Div().ID(prop.Name).Class("accordion-item"), prop.Properties, accordionDivID, depth+1) + element := render(app.Div().ID(prop.Name).Class("accordion-item"), prop.Properties, targetID, depth+1) bodyElements = append(bodyElements, element) } diff --git a/wasm/app.js b/wasm/app.js index 6ba2532..86708ff 100644 --- a/wasm/app.js +++ b/wasm/app.js @@ -5,7 +5,7 @@ var goappNav = function () {}; var goappOnUpdate = function () {}; var goappOnAppInstallChange = function () {}; -const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"88fd944df3b3589e7578486efd86022ea07b8649"}; +const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"f12aae0089af3c57e2d86eef472876387bf42dc1"}; const goappLoadingLabel = "{progress}%"; const goappWasmContentLengthHeader = ""; diff --git a/wasm/index.html b/wasm/index.html index d385100..d3f7d8b 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -1,5 +1,5 @@ - +
@@ -7,25 +7,25 @@ - +