From 548a45d5f16d7e0c7b05e4611b078e75e2393b29 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Mon, 25 Dec 2023 18:37:36 +0100 Subject: [PATCH] add changes in docs, fix tests and bump version Signed-off-by: Aleksandar Stojanov --- .pre-commit-config.yaml | 2 +- README.md | 2 +- docs/README.md | 36 ++++++++++++++++++++++++++++++++++++ pkg/schema.go | 5 +---- pkg/schema_test.go | 2 +- plugin.yaml | 2 +- testdata/anchors.schema.json | 26 ++++++++++++++++++++++++++ testdata/anchors.yaml | 4 ++++ 8 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 testdata/anchors.schema.json create mode 100644 testdata/anchors.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b64d278..51daba5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/losisin/helm-values-schema-json - rev: v1.0.0 + rev: v1.1.0 hooks: - id: helm-schema args: diff --git a/README.md b/README.md index 793c1fc..37350c8 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ First [install pre-commit](https://pre-commit.com/#install) and then create or u ```yaml repos: - repo: https://github.com/losisin/helm-values-schema-json - rev: v1.0.0 + rev: v1.1.0 hooks: - id: helm-schema args: ["-input", "values.yaml"] diff --git a/docs/README.md b/docs/README.md index 2717e18..fb67a53 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,6 +70,42 @@ replicaCount: # @schema type:[integer, null] } ``` +Another way to use this is to define type when using anchors and pointers in yaml. See discussion [#28](https://github.com/losisin/helm-values-schema-json/issues/28) for more details. + +```yaml +app: &app + settings: + namespace: + - *app # @schema type:[string] +``` + +```json +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "app": { + "properties": { + "settings": { + "properties": { + "namespace": { + "items": { + "type": [ + "string" + ] + }, + "type": "array" + } + }, + "type": "object" + } + }, + "type": "object" + } + }, + "type": "object" +} +``` + ### Enum Always returns array of strings. Special case is `null` where instead of string, it is treated as valid inpput type. [section 6.1.2](https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.2) diff --git a/pkg/schema.go b/pkg/schema.go index 41074a8..c177145 100644 --- a/pkg/schema.go +++ b/pkg/schema.go @@ -203,10 +203,7 @@ func parseNode(keyNode *yaml.Node, valNode *yaml.Node) (*Schema, bool) { } } - propIsRequired := false - if keyNode != nil { - propIsRequired = processComment(schema, getComment(keyNode, valNode)) - } + propIsRequired := processComment(schema, getComment(keyNode, valNode)) return schema, propIsRequired } diff --git a/pkg/schema_test.go b/pkg/schema_test.go index e608a2c..26e7a5c 100644 --- a/pkg/schema_test.go +++ b/pkg/schema_test.go @@ -161,7 +161,7 @@ func TestGetComment(t *testing.T) { Value: "some value", LineComment: "", }, - expectedComment: "", + expectedComment: "# Key comment", }, { name: "empty value node, key node with comment", diff --git a/plugin.yaml b/plugin.yaml index e0d8384..0908b87 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "schema" -version: "1.0.0" +version: "1.1.0" usage: "generate values.schema.json from values yaml" description: "Helm plugin for generating values.schema.json from multiple values files." ignoreFlags: false diff --git a/testdata/anchors.schema.json b/testdata/anchors.schema.json new file mode 100644 index 0000000..c78bce8 --- /dev/null +++ b/testdata/anchors.schema.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "app": { + "properties": { + "settings": { + "properties": { + "namespace": { + "items": { + "type": [ + "string" + ] + }, + "type": "array" + } + }, + "type": [ + "integer" + ] + } + }, + "type": "object" + } + }, + "type": "object" +} \ No newline at end of file diff --git a/testdata/anchors.yaml b/testdata/anchors.yaml new file mode 100644 index 0000000..96e918e --- /dev/null +++ b/testdata/anchors.yaml @@ -0,0 +1,4 @@ +app: &app # @schema type:[integer] + settings: + namespace: + - *app # @schema type:[string]