Skip to content

Commit

Permalink
add changes in docs, fix tests and bump version
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Dec 25, 2023
1 parent 78fed75 commit 548a45d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
36 changes: 36 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions pkg/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions testdata/anchors.schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 4 additions & 0 deletions testdata/anchors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app: &app # @schema type:[integer]
settings:
namespace:
- *app # @schema type:[string]

0 comments on commit 548a45d

Please sign in to comment.