| 8 | ) |
| 9 | |
| 10 | func (s Spec) JSONSchemaExtend(sc *jsonschema.Schema) { |
| 11 | s.FileSpec.JSONSchemaExtend(sc) // need to call manually |
| 12 | |
| 13 | batchTimeout := sc.Properties.Value("batch_timeout").OneOf[0] // 0 - val, 1 - null |
| 14 | batchTimeout.Default = "30s" |
| 15 | |
| 16 | // no_rotate:true -> only nulls for batch options |
| 17 | noRotateNoBatch := &jsonschema.Schema{ |
| 18 | Title: "Disallow batching when using no_rotate", |
| 19 | If: &jsonschema.Schema{ |
| 20 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 21 | noRotate := *sc.Properties.Value("no_rotate") |
| 22 | noRotate.Default = nil |
| 23 | noRotate.Const = true |
| 24 | noRotate.Description = "" |
| 25 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 26 | properties.Set("no_rotate", &noRotate) |
| 27 | return properties |
| 28 | }(), |
| 29 | Required: []string{"no_rotate"}, |
| 30 | }, |
| 31 | Then: &jsonschema.Schema{ |
| 32 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 33 | // we make the non-zero requirement, so we want to allow only null here |
| 34 | null := &jsonschema.Schema{Type: "null"} |
| 35 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 36 | properties.Set("batch_size", null) |
| 37 | properties.Set("batch_size_bytes", null) |
| 38 | properties.Set("batch_timeout", null) |
| 39 | return properties |
| 40 | }(), |
| 41 | }, |
| 42 | Extras: map[string]any{ |
| 43 | "errorMessage": map[string]any{ |
| 44 | "properties": map[string]any{ |
| 45 | "no_rotate": "batching options must not be present when no_rotate is enabled", |
| 46 | "batch_size": "batching options must not be present when no_rotate is enabled", |
| 47 | "batch_size_bytes": "batching options must not be present when no_rotate is enabled", |
| 48 | "batch_timeout": "batching options must not be present when no_rotate is enabled", |
| 49 | }, |
| 50 | }, |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | // path patterns: should be a clean path |
| 55 | cleanPath := &jsonschema.Schema{ |
| 56 | Title: "`path` is a clean path value", |
| 57 | Extras: map[string]any{ |
| 58 | "errorMessage": map[string]any{ |
| 59 | "properties": map[string]any{ |
| 60 | "path": "value must not contain ./ or //", |
| 61 | }, |
| 62 | }, |
| 63 | }, |
| 64 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 65 | // we make the non-zero requirement, so we want to allow only null here |
| 66 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 67 | properties.Set("path", &jsonschema.Schema{ |