diff --git a/README.md b/README.md index cb672a0..7595bae 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ file, you can do the following: 1. Install [`pre-commit`](https://pre-commit.com/#install) 2. Copy the [`.pre-commit-config.yaml`](./.pre-commit-config.yaml) to your helm chart repository. 3. Then run these commands: + ```sh pre-commit install pre-commit install-hooks @@ -73,6 +74,7 @@ Flags: -n, --no-dependencies "don't analyze dependencies" -o, --output-file string "jsonschema file path relative to each chart directory to which jsonschema will be written (default 'values.schema.json')" -f, --value-files strings "filenames to check for chart values (default [values.yaml])" + -k, --skip-auto-generation strings "skip the auto generation for these fields (default [])" -v, --version "version for helm-schema" ``` @@ -92,32 +94,32 @@ The `jsonschema` must be between two entries of : `# @schema`, example below : ### Available annotations -|Key|Description|Values| -|-|-|-| -|`type`|Defines the [jsonschema-type](https://json-schema.org/understanding-json-schema/reference/type.html) of the object|`object`, `array`, `string`, `number`, `integer`, `boolean` or `null`| -|`title`|Defines the [title field](https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=title) of the object|Defaults to the key itself| -|`description`|Defines the [description field](https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=description) of the object.|Defaults to the comment which has no `# @schema` prefix| -|`default`|Sets the default value and will be displayed first on the users IDE|| -|`properties`|Contains a map with keys as property names and values as schema|Takes an `object`| -|`pattern`|Regex pattern to test the value|Takes an `string`| -|`format`|The [format keyword](https://json-schema.org/understanding-json-schema/reference/string.html#format) allows for basic semantic identification of certain kinds of string values|| -|`required`|Adds the key to the required items|`true` or `false`| -|`deprecated`|Marks the option as deprecated|`true` or `false`| -|`items`|Contains the schema that describes the possible array items|| -|`enum`|Multiple allowed values|| -|`const`|Single allowed value|| -|`examples`|Some examples you can provide for the end user|Takes an `array`| -|`minimum`|Minimum value. Can't be used with `exclusiveMinimum`|Must be smaller than `maximum` or `exclusiveMaximum` (if used)| -|`exclusiveMinimum`|Exclusive minimum. Can't be used with `minimum`|Must be smaller than `maximum` or `exclusiveMaximum` (if used)| -|`maximum`|Maximum value. Can't be used with `exclusiveMaximum`|Must be bigger than `minimum` or `exclusiveMinimum` (if used)| -|`exclusiveMaximum`|Exclusive maximum value. Can't be used with `maximum`|Must be bigger than `minimum` or `exclusiveMinimum` (if used)| -|`multipleOf`|The yaml-value must be a multiple of. For example: If you set this to 10, allowed values would be 0, 10, 20, 30...|Takes an `int`| -|`additionalProperties`|Allow additional keys in maps. Useful if you want to use for example `additionalAnnotations`, which will be filled with keys that the `jsonschema` can't know|Defaults to `false` if the map is not an empty map. Takes a schema or boolean value| -|`patternProperties`|Contains a map which maps schemas to pattern. If properties match the patterns, the given schema is applied|Takes an `object`| -|`anyOf`|Accepts an array of schemas. None or one must apply|Takes an `array`| -|`oneOf`|Accepts an array of schemas. One or more must apply|Takes an `array`| -|`allOf`|Accepts an array of schemas. All must apply|Takes an `array`| -|`if/then/else`|`if` the given schema applies, `then` also apply the given schema or `else` the other schema|| +| Key | Description | Values | +| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| `type` | Defines the [jsonschema-type](https://json-schema.org/understanding-json-schema/reference/type.html) of the object | `object`, `array`, `string`, `number`, `integer`, `boolean` or `null` | +| `title` | Defines the [title field](https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=title) of the object | Defaults to the key itself | +| `description` | Defines the [description field](https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=description) of the object. | Defaults to the comment which has no `# @schema` prefix | +| `default` | Sets the default value and will be displayed first on the users IDE | | +| `properties` | Contains a map with keys as property names and values as schema | Takes an `object` | +| `pattern` | Regex pattern to test the value | Takes an `string` | +| `format` | The [format keyword](https://json-schema.org/understanding-json-schema/reference/string.html#format) allows for basic semantic identification of certain kinds of string values | | +| `required` | Adds the key to the required items | `true` or `false` | +| `deprecated` | Marks the option as deprecated | `true` or `false` | +| `items` | Contains the schema that describes the possible array items | | +| `enum` | Multiple allowed values | | +| `const` | Single allowed value | | +| `examples` | Some examples you can provide for the end user | Takes an `array` | +| `minimum` | Minimum value. Can't be used with `exclusiveMinimum` | Must be smaller than `maximum` or `exclusiveMaximum` (if used) | +| `exclusiveMinimum` | Exclusive minimum. Can't be used with `minimum` | Must be smaller than `maximum` or `exclusiveMaximum` (if used) | +| `maximum` | Maximum value. Can't be used with `exclusiveMaximum` | Must be bigger than `minimum` or `exclusiveMinimum` (if used) | +| `exclusiveMaximum` | Exclusive maximum value. Can't be used with `maximum` | Must be bigger than `minimum` or `exclusiveMinimum` (if used) | +| `multipleOf` | The yaml-value must be a multiple of. For example: If you set this to 10, allowed values would be 0, 10, 20, 30... | Takes an `int` | +| `additionalProperties` | Allow additional keys in maps. Useful if you want to use for example `additionalAnnotations`, which will be filled with keys that the `jsonschema` can't know | Defaults to `false` if the map is not an empty map. Takes a schema or boolean value | +| `patternProperties` | Contains a map which maps schemas to pattern. If properties match the patterns, the given schema is applied | Takes an `object` | +| `anyOf` | Accepts an array of schemas. None or one must apply | Takes an `array` | +| `oneOf` | Accepts an array of schemas. One or more must apply | Takes an `array` | +| `allOf` | Accepts an array of schemas. All must apply | Takes an `array` | +| `if/then/else` | `if` the given schema applies, `then` also apply the given schema or `else` the other schema | | ## Validation & completion @@ -129,7 +131,6 @@ You'll have to place this line at the top of your `values.yaml` (`$schema= 0 { @@ -478,13 +488,13 @@ func YamlToSchema( seqSchema.AnyOf = append(seqSchema.AnyOf, &Schema{Type: itemNodeType}) } else { itemRequiredProperties := []string{} - itemSchema := YamlToSchema(itemNode, keepFullComment, dontRemoveHelmDocsPrefix, &itemRequiredProperties) + itemSchema := YamlToSchema(itemNode, keepFullComment, dontRemoveHelmDocsPrefix, skipAutoGeneration, &itemRequiredProperties) if len(itemRequiredProperties) > 0 { itemSchema.RequiredProperties = itemRequiredProperties } - if itemNode.Kind == yaml.MappingNode && (!itemSchema.HasData || itemSchema.AdditionalProperties == nil) { + if !slices.Contains(skipAutoGeneration, "additionalProperties") && itemNode.Kind == yaml.MappingNode && (!itemSchema.HasData || itemSchema.AdditionalProperties == nil) { itemSchema.AdditionalProperties = new(bool) }