| 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 | pathWithUUID := &jsonschema.Schema{ |
| 17 | Title: "Require {{UUID}} to be present in path", |
| 18 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 19 | // we make the non-zero requirement, so we want to allow only null here |
| 20 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 21 | properties.Set("path", &jsonschema.Schema{ |
| 22 | Type: "string", |
| 23 | Pattern: `^.*\{\{UUID\}\}.*$`, |
| 24 | }) |
| 25 | return properties |
| 26 | }(), |
| 27 | } |
| 28 | |
| 29 | pathNotWithUUID := &jsonschema.Schema{ |
| 30 | Title: "Disallow {{UUID}} in path", |
| 31 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 32 | // we make the non-zero requirement, so we want to allow only null here |
| 33 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 34 | properties.Set("path", &jsonschema.Schema{ |
| 35 | Type: "string", |
| 36 | Not: &jsonschema.Schema{ |
| 37 | Pattern: `^.*\{\{UUID\}\}.*$`, |
| 38 | }, |
| 39 | }) |
| 40 | return properties |
| 41 | }(), |
| 42 | } |
| 43 | |
| 44 | // no_rotate:true -> no {{UUID}} should be present in path |
| 45 | noRotateNoUUID := &jsonschema.Schema{ |
| 46 | Title: "Disallow {{UUID}} in path when using no_rotate", |
| 47 | If: &jsonschema.Schema{ |
| 48 | Properties: func() *orderedmap.OrderedMap[string, *jsonschema.Schema] { |
| 49 | noRotate := *sc.Properties.Value("no_rotate") |
| 50 | noRotate.Default = nil |
| 51 | noRotate.Const = true |
| 52 | noRotate.Description = "" |
| 53 | properties := orderedmap.New[string, *jsonschema.Schema]() |
| 54 | properties.Set("no_rotate", &noRotate) |
| 55 | return properties |
| 56 | }(), |
| 57 | Required: []string{"no_rotate"}, |
| 58 | }, |
| 59 | Then: pathNotWithUUID, |
| 60 | Extras: map[string]any{ |
| 61 | "errorMessage": map[string]any{ |
| 62 | "properties": map[string]any{ |
| 63 | "path": "the {{UUID}} placeholder must not be present in the path when no_rotate is enabled", |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | } |