losisin / helm-values-schema-json

Helm plugin for generating values.schema.json from multiple values files
MIT License
75 stars 11 forks source link

`default: null` doesn't work #67

Closed RothAndrew closed 5 months ago

RothAndrew commented 5 months ago

If I use:

foo: null # @schema type: [string, null]; default: null

The default is not recorded in the schema.

I can use default: "null" which does work, but it makes it look like the default should be the string "null" rather than null which is not a string in YAML-land.

This issue looks to be unique to null. If I have a boolean like:

foo: true # @schema type: [boolean]; default: true

That works fine, and correctly says the default is true, not "true"

losisin commented 5 months ago

@RothAndrew Is the issue how you declare it in comment or generated schema? I think it boils down to the yaml library because null and absent will be translated in go to nil. If I remove that check, then every property will get "Default: null to the schema even if you don't use it comment. Can you provide more info or use case?

RothAndrew commented 5 months ago

EDIT: nevermind, skip to the bottom. Even if this tool did what I thought I wanted it to do, the jsonschema2md tool just discards the default key if its value is null.


Hello!

My use case is that I'm using this tool, followed by Adobe's jsonschema2md to do my documentation. It suits my needs better than helm-docs.

Several of my helm values default to null. If I do this in the values.yaml:

someValue: null # @schema type: [string, null]; default: null

The default never shows up in the .schema.json file.

image

If I do this instead:

someValue: null # @schema type: [string, null]; default: "null"

the .schema.json value has a default, but it is the string "null" instead of JSON's null.

image

My markdown documentation then makes it seem like the default value is the string "null"

image

If I manually edit the .schema.json file to:

image

...the default doesn't show up in the markdown at all... Maybe this is a limitation of JSON schema.. Okay nevermind, I'll figure out how to document this in a different way.

image