Skip to content

Commit

Permalink
add using example after default if it is defined (#56)
Browse files Browse the repository at this point in the history
* add using example after default if it is defined

* added release doc and rebuilt the WASM part

* fixed the ID and regenerated the site
  • Loading branch information
Skarlso authored Feb 24, 2024
1 parent 2621525 commit 620b32a
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 21 deletions.
3 changes: 3 additions & 0 deletions docs/release_notes/v0.3.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v0.3.3 Release

- Add using `example`s if defined after `default` value in the schema. (#56)
4 changes: 4 additions & 0 deletions pkg/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions pkg/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
91 changes: 91 additions & 0 deletions pkg/testdata/sample_crd_with_example.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
15 changes: 15 additions & 0 deletions pkg/testdata/sample_crd_with_example_golden.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
6 changes: 3 additions & 3 deletions wasm/app-worker.js
Original file line number Diff line number Diff line change
@@ -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/[email protected]/dist/js/bootstrap.bundle.min.js","https://cdn.jsdelivr.net/npm/[email protected]/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
Expand All @@ -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) => {
Expand Down
13 changes: 6 additions & 7 deletions wasm/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion wasm/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
20 changes: 10 additions & 10 deletions wasm/index.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<!DOCTYPE html>
<html data-bs-theme="dark" lang="en" data-bs-core="modern">
<html data-bs-core="modern" data-bs-theme="dark" lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="Gergely Brautigam">
<meta name="description" content>
<meta name="keywords" content>
<meta name="theme-color" content="#2d2c2c">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover">
<meta property="og:url" content="http://127.0.0.1:55377/">
<meta property="og:url" content="http://127.0.0.1:55423/">
<meta property="og:title" content="Preview CRDs">
<meta property="og:description" content>
<meta property="og:type" content="website">
<meta property="og:image" content>
<title>Preview CRDs</title>
<link type="text/css" rel="preload" href="/app.css" as="style">
<link as="style" type="text/css" rel="preload" href="/app.css">
<link type="text/css" rel="preload" href="/web/css/alert.css" as="style">
<link type="text/css" rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" as="style">
<link as="style" type="text/css" rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css">
<link as="style" type="text/css" rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" as="style" type="text/css">
<link type="text/css" rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" as="style">
<link rel="icon" href="https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.svg">
<link rel="apple-touch-icon" href="/web/img/logo.png">
<link rel="manifest" href="/manifest.webmanifest">
<link href="/manifest.webmanifest" rel="manifest">
<link rel="stylesheet" type="text/css" href="/app.css">
<link rel="stylesheet" type="text/css" href="/web/css/alert.css">
<link type="text/css" href="/web/css/alert.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script defer src="/wasm_exec.js"></script>
<script defer src="/app.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
Expand Down Expand Up @@ -62,7 +62,7 @@
<body>
<main></main>
<aside id="app-wasm-loader" class="goapp-app-info">
<img src="/web/img/logo.png" id="app-wasm-loader-icon" class="goapp-logo goapp-spin">
<img id="app-wasm-loader-icon" class="goapp-logo goapp-spin" src="/web/img/logo.png">
<p id="app-wasm-loader-label" class="goapp-label">0%</p>
</aside>
</body>
Expand Down
Binary file modified wasm/web/app.wasm
Binary file not shown.

0 comments on commit 620b32a

Please sign in to comment.