github.com/TykTechnologies/tyk/apidef/streams/bento/schema
No package summary is available.
Package
Files: 1. Third party imports: 7. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
const defaultOutput = "bento-config-schema.json"
Vars
var _ customValidationRule = (*addURIFormatToHTTPClientRule)(nil)
var definitions = []string{
"processor",
"scanner",
}
var properties = []string{
"http",
"input",
"input_resources",
"output",
"output_resources",
"processor_resources",
"shutdown_delay",
"shutdown_timeout",
"pipeline",
}
var result = []byte(`{}`)
var supportedSources = []string{
"broker",
"http_client",
"http_server",
"kafka",
"amqp_0_9",
"amqp_1",
"mqtt",
}
Types
addURIFormatToHTTPClientRule
addURIFormatToHTTPClientRule represents a custom rule for adding URI format validation to HTTP client URL properties in a schema.
type addURIFormatToHTTPClientRule struct{}
arguments
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| help |
|
No comment on field. |
| output |
|
No comment on field. |
type arguments struct {
help bool
output string
}
customValidationRule
customValidationRule is an interface for defining custom validation rules for JSON schemas.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type customValidationRule interface {
// Name returns the name of the validation rule.
Name() string
// Apply applies the validation rule to the provided input data and
// returns the processed data or an error if validation fails.
Apply(input []byte) ([]byte, error)
}
Functions
func (*addURIFormatToHTTPClientRule) Apply
func (a *addURIFormatToHTTPClientRule) Apply(input []byte) ([]byte, error) {
for _, kind := range []string{"input", "output"} {
data, dataType, _, err := jsonparser.Get(input, "definitions", kind, "properties", "http_client", "properties", "url")
if err != nil {
return nil, fmt.Errorf("error while applying %s rule, getting URL property returned: %w", a.Name(), err)
}
if dataType != jsonparser.Object {
return nil, fmt.Errorf("error while applying %s rule, URL property is not an object", a.Name())
}
input, err = a.setModifiedURLSection(input, data, "definitions", kind, "properties", "http_client", "properties", "url")
if err != nil {
return nil, fmt.Errorf("error while applying %s rule, setting URL property returned: %w", a.Name(), err)
}
}
return input, nil
}
Cognitive complexity: 10, Cyclomatic complexity: 5
func (*addURIFormatToHTTPClientRule) Name
func (a *addURIFormatToHTTPClientRule) Name() string {
return "add_uri_format_to_http_client"
}
Cognitive complexity: 0, Cyclomatic complexity: 1
Private functions
func findTemplate
findTemplate (kind string, data []byte) ([]byte, error)
References: errors.Is, jsonparser.ArrayEach, jsonparser.Get, jsonparser.KeyPathNotFoundError, jsonparser.ValueType.
func generateBentoConfigSchema
generateBentoConfigSchema (output string, rules []customValidationRule) error
References: fmt.Errorf, jsonparser.ObjectEach, jsonparser.Set, jsonparser.ValueType, service.GlobalEnvironment.
func insertDefinitionKind
insertDefinitionKind (kind string, anyOfItems []byte) error
References: errors.Is, jsonparser.ArrayEach, jsonparser.Get, jsonparser.KeyPathNotFoundError, jsonparser.Set, jsonparser.ValueType.
func insertDefinitions
insertDefinitions (data []byte) error
References: jsonparser.Set.
func main
How to use this program?
generate_bento_config_schema generates a JSON schema for the Input/Output resources we support.
Simply,
go run generate_bento_config.go
It'll generate a bento-config-schema.json file in the current working folder. You can also set
an output path via -output-path <string> parameter.
Run via task runner:
task generate-bento-config-validator-schema
The task will automatically update apidef/streams/bento/schema/bento-config-schema.json file.
main ()
References: flag.ContinueOnError, flag.NewFlagSet, fmt.Fprintf, ioutil.Discard, os.Args, os.Exit, os.Stdout.
func printErrorAndExit
printErrorAndExit (err error)
References: fmt.Fprint, os.Exit, os.Stdout.
func saveFile
saveFile (outputPath string) error
References: bytes.NewBuffer, fmt.Errorf, json.Indent, os.Create.
func scanDefinitions
scanDefinitions (data []byte) error
References: jsonparser.ObjectEach, jsonparser.Set, jsonparser.ValueType.
func scanDefinitionsForKind
scanDefinitionsForKind (kind string, data []byte) error
References: errors.Is, fmt.Errorf, jsonparser.Array, jsonparser.ArrayEach, jsonparser.Get, jsonparser.KeyPathNotFoundError, jsonparser.Object, jsonparser.ValueType.
func scanProperties
scanProperties (data []byte) error
References: jsonparser.ObjectEach, jsonparser.Set, jsonparser.ValueType.
func usage
usage ()
References: fmt.Fprintf, os.Stdout.
func setModifiedURLSection
setModifiedURLSection (input,data []byte, keys ...string) ([]byte, error)
References: jsonparser.Set.
Tests
Files: 1. Third party imports: 2. Imports from organisation: 0. Tests: 3. Benchmarks: 0.