github.com/TykTechnologies/tyk/apidef/streams
No package summary is available.
Package
Files: 1. Third party imports: 3. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
const (
keyStreams = "streams"
keyDefinitions = "definitions"
keyProperties = "properties"
keyRequired = "required"
oasSchemaVersionNotFoundFmt = "schema not found for version %q"
)
Vars
var (
schemaOnce sync.Once
oasJSONSchemas map[string][]byte
bentoValidators map[bento.ValidatorKind]bento.ConfigValidator
defaultVersion string
)
var schemaDir embed.FS
Functions
func GetOASSchema
GetOASSchema returns an oas schema for a particular version.
func GetOASSchema(version string) ([]byte, error) {
if err := loadSchemas(); err != nil {
return nil, fmt.Errorf("loadSchemas failed: %w", err)
}
if version == "" {
return oasJSONSchemas[defaultVersion], nil
}
minorVersion, err := getMinorVersion(version)
if err != nil {
return nil, err
}
oasSchema, ok := oasJSONSchemas[minorVersion]
if !ok {
return nil, fmt.Errorf(oasSchemaVersionNotFoundFmt, version)
}
return oasSchema, nil
}
Cognitive complexity: 8, Cyclomatic complexity: 5
func ValidateOASObject
ValidateOASObject validates a Tyk Streams document against a particular OAS version.
func ValidateOASObject(documentBody []byte, oasVersion string) error {
return ValidateOASObjectWithBentoConfigValidator(documentBody, oasVersion, bento.DefaultValidator)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func ValidateOASObjectWithBentoConfigValidator
ValidateOASObjectWithBentoConfigValidator validates a Tyk Streams document against a particular OAS version and takes an optional ConfigValidator
func ValidateOASObjectWithBentoConfigValidator(documentBody []byte, oasVersion string, bentoValidatorKind bento.ValidatorKind) error {
oasSchema, err := GetOASSchema(oasVersion)
if err != nil {
return err
}
return validateJSON(oasSchema, documentBody, bentoValidatorKind)
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func ValidateOASObjectWithConfig
ValidateOASObjectWithConfig validates a Tyk Streams document against a particular OAS version, using the provided configuration to determine if validation should be disabled.
func ValidateOASObjectWithConfig(documentBody []byte, oasVersion string, disableValidator bool) error {
validatorKind := bento.DefaultValidator
if disableValidator {
validatorKind = bento.EnableAll
}
return ValidateOASObjectWithBentoConfigValidator(documentBody, oasVersion, validatorKind)
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func ValidateOASTemplate
ValidateOASTemplate checks a Tyk Streams OAS API template for necessary fields, acknowledging that some standard Tyk OAS API fields are optional in templates.
func ValidateOASTemplate(documentBody []byte, oasVersion string) error {
return ValidateOASTemplateWithBentoValidator(documentBody, oasVersion, bento.DefaultValidator)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func ValidateOASTemplateWithBentoValidator
func ValidateOASTemplateWithBentoValidator(documentBody []byte, oasVersion string, bentoValidatorKind bento.ValidatorKind) error {
oasSchema, err := GetOASSchema(oasVersion)
if err != nil {
return err
}
oasSchema = jsonparser.Delete(oasSchema, keyProperties, oas.ExtensionTykStreaming, keyRequired)
oasSchema = jsonparser.Delete(oasSchema, keyProperties, oas.ExtensionTykAPIGateway, keyRequired)
definitions, _, _, err := jsonparser.Get(oasSchema, keyDefinitions)
if err != nil {
return err
}
unsetReqFieldsPaths := []string{
"X-Tyk-Info",
"X-Tyk-State",
"X-Tyk-Server",
"X-Tyk-ListenPath",
"X-Tyk-Streams",
}
for _, path := range unsetReqFieldsPaths {
definitions = jsonparser.Delete(definitions, path, keyRequired)
}
oasSchema, err = jsonparser.Set(oasSchema, definitions, keyDefinitions)
if err != nil {
return err
}
return validateJSON(oasSchema, documentBody, bentoValidatorKind)
}
Cognitive complexity: 10, Cyclomatic complexity: 5
Private functions
func findDefaultVersion
findDefaultVersion (rawVersions []string) string
References: pkgver.Collection, pkgver.NewVersion, pkgver.Version, sort.Sort.
func getMinorVersion
getMinorVersion (version string) (string, error)
References: fmt.Sprintf, pkgver.NewVersion.
func loadSchemas
loadSchemas () error
References: bento.ConfigValidator, bento.DefaultValidator, bento.EnableAll, bento.NewDefaultConfigValidator, bento.NewEnableAllConfigValidator, bento.ValidatorKind, filepath.Join, fmt.Errorf, fmt.Sprintf, jsonparser.Delete, jsonparser.ObjectEach, jsonparser.Set, jsonparser.ValueType, oas.ExtensionTykAPIGateway, oas.ExtensionTykStreaming, strings.HasSuffix, strings.TrimSuffix.
func setDefaultVersion
setDefaultVersion ()
func validateBentoConfiguration
validateBentoConfiguration (document []byte, bentoValidatorKind bento.ValidatorKind) error
References: bento.EnableAll, errors.Is, fmt.Errorf, jsonparser.Get, jsonparser.KeyPathNotFoundError, jsonparser.ObjectEach, jsonparser.ValueType, oas.ExtensionTykStreaming.
func validateJSON
validateJSON (schema,document []byte, bentoValidatorKind bento.ValidatorKind) error
References: errors.New, gojsonschema.NewBytesLoader, gojsonschema.Validate, multierror.Append, multierror.Error, tykerrors.Formatter.
Tests
Files: 1. Third party imports: 5. Imports from organisation: 1. Tests: 9. Benchmarks: 0.
Vars
var oasTemplateFS embed.FS