allowNullValues wraps the top-level additionalProperties of a map schema with anyOf: [originalSchema, {type: "null"}] so that setting a key to null is valid (e.g. "bg@foo": null to remove a default entry).
(schema *jsonschema.Schema)
| 109 | // anyOf: [originalSchema, {type: "null"}] so that setting a key to null is valid |
| 110 | // (e.g. "bg@foo": null to remove a default entry). |
| 111 | func allowNullValues(schema *jsonschema.Schema) { |
| 112 | if schema.AdditionalProperties != nil && schema.AdditionalProperties != jsonschema.TrueSchema && schema.AdditionalProperties != jsonschema.FalseSchema { |
| 113 | original := schema.AdditionalProperties |
| 114 | schema.AdditionalProperties = &jsonschema.Schema{ |
| 115 | AnyOf: []*jsonschema.Schema{ |
| 116 | original, |
| 117 | {Type: "null"}, |
| 118 | }, |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func generateSchema(template any, dir string, allowNull bool) error { |
| 124 | settingsSchema := jsonschema.Reflect(template) |
no outgoing calls
no test coverage detected