github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/scenarios.go (about)

     1  package model
     2  
     3  const (
     4  	// ScenariosKey is scenarios label key
     5  	ScenariosKey = "scenarios"
     6  )
     7  
     8  var (
     9  	// SchemaForScenariosSchema is used to validate ScenariosSchema (allows only modifications to enum field)
    10  	SchemaForScenariosSchema = map[string]interface{}{
    11  		"type":                 "object",
    12  		"additionalProperties": false,
    13  		"required":             []string{"type", "minItems", "uniqueItems", "items"},
    14  		"properties": map[string]interface{}{
    15  			"type": map[string]interface{}{
    16  				"const": "array",
    17  			},
    18  			"minItems": map[string]interface{}{
    19  				"const": 1,
    20  			},
    21  			"uniqueItems": map[string]interface{}{
    22  				"const": true,
    23  			},
    24  			"items": map[string]interface{}{
    25  				"type":                 "object",
    26  				"additionalProperties": false,
    27  				"required":             []string{"type", "enum"},
    28  				"properties": map[string]interface{}{
    29  					"type": map[string]interface{}{
    30  						"const": "string",
    31  					},
    32  					"pattern": map[string]interface{}{
    33  						"const": "^[A-Za-z0-9]([-_A-Za-z0-9\\s]*[A-Za-z0-9])$",
    34  					},
    35  					"maxLength": map[string]interface{}{
    36  						"const": 128,
    37  					},
    38  					"enum": map[string]interface{}{
    39  						"type": "array",
    40  						"items": map[string]interface{}{
    41  							"type":      "string",
    42  							"pattern":   "^[A-Za-z0-9]([-_A-Za-z0-9\\s]*[A-Za-z0-9])$",
    43  							"maxLength": 128,
    44  						},
    45  						"contains": map[string]interface{}{},
    46  					},
    47  				},
    48  			},
    49  		},
    50  	}
    51  )
    52  
    53  // NewScenariosSchema returns new scenario schema for given scenarios
    54  func NewScenariosSchema(scenarios []string) map[string]interface{} {
    55  	return map[string]interface{}{
    56  		"type":        "array",
    57  		"minItems":    1,
    58  		"uniqueItems": true,
    59  		"items": map[string]interface{}{
    60  			"type":      "string",
    61  			"pattern":   "^[A-Za-z0-9]([-_A-Za-z0-9\\s]*[A-Za-z0-9])$",
    62  			"enum":      scenarios,
    63  			"maxLength": 128,
    64  		},
    65  	}
    66  }