-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[testing] Validation schema strictness improvements #6898
base: master
Are you sure you want to change the base?
Conversation
A JIRA Issue ID is missing from your branch name, PR title and PR description! 🦄 Your branch: test/schema-strictness-and-validation Your PR title: [testing] Validation schema strictness improvements Your PR description: null If this is your first time contributing to this repository - welcome! Please refer to jira-lint to get started. Without the JIRA Issue ID in your branch name you would lose out on automatic updates to JIRA via SCM; some GitHub status checks might fail. Valid sample branch names:‣ feature/shiny-new-feature--mojo-10' |
API Changes --- prev.txt 2025-02-20 16:23:14.384734736 +0000
+++ current.txt 2025-02-20 16:23:10.275734710 +0000
@@ -855,10 +855,13 @@
type JSVMEventHandlerConf struct {
// Disabled indicates whether the event handler is inactive.
Disabled bool `bson:"disabled" json:"disabled"`
+
// ID is the optional unique identifier for the event handler.
ID string `bson:"id" json:"id"`
- // MethodName specifies the JavaScript function name to be executed.
- MethodName string `bson:"name" json:"name"`
+
+ // Name specifies the JavaScript function name to be executed.
+ Name string `bson:"name" json:"name"`
+
// Path refers to the file path of the JavaScript source code for the handler.
Path string `bson:"path" json:"path"`
}
@@ -1518,18 +1521,25 @@
type WebHookHandlerConf struct {
// Disabled enables/disables this webhook.
Disabled bool `bson:"disabled" json:"disabled"`
+
// ID optional ID of the webhook, to be used in pro mode.
ID string `bson:"id" json:"id"`
+
// Name is the name of webhook.
Name string `bson:"name" json:"name"`
+
// The method to use for the webhook.
Method string `bson:"method" json:"method"`
+
// The target path on which to send the request.
TargetPath string `bson:"target_path" json:"target_path"`
+
// The template to load in order to format the request.
TemplatePath string `bson:"template_path" json:"template_path"`
+
// Headers to set when firing the webhook.
HeaderList map[string]string `bson:"header_map" json:"header_map"`
+
// The cool-down for the event so it does not trigger again (in seconds).
EventTimeout int64 `bson:"event_timeout" json:"event_timeout"`
}
@@ -2025,6 +2035,10 @@
GetValidationOptionsFromConfig retrieves validation options based on the
configuration settings.
+func LoadOASSchema(_ testing.TB, strict bool) error
+ LoadOASSchema is a testing hook to increase schema strictness. This allows
+ reporting unrecognized fields during development.
+
func MigrateAndFillOAS(api *apidef.APIDefinition) (APIDef, []APIDef, error)
MigrateAndFillOAS migrates classic APIs to OAS-compatible forms. Then,
it fills an OAS with it. To be able to make it a valid OAS, it adds some
@@ -4723,8 +4737,10 @@
type WebhookEvent struct {
// URL is the target URL for the webhook.
URL string `json:"url" bson:"url"`
+
// Method is the HTTP method for the webhook.
Method string `json:"method" bson:"method"`
+
// CoolDownPeriod defines cool-down for the event, so it does not trigger again.
// It uses shorthand notation.
// The value of CoolDownPeriod is a string that specifies the interval in a compact form,
@@ -4742,8 +4758,10 @@
// It's important to format the string correctly, as invalid formats will
// be considered as 0s/empty.
CoolDownPeriod ReadableDuration `json:"cooldownPeriod" bson:"cooldownPeriod"`
+
// BodyTemplate is the template to be used for request payload.
BodyTemplate string `json:"bodyTemplate,omitempty" bson:"bodyTemplate,omitempty"`
+
// Headers are the list of request headers to be used.
Headers Headers `json:"headers,omitempty" bson:"headers,omitempty"`
} |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
@@ -278,7 +280,9 @@ func TestFixtures(t *testing.T) { | |||
if tc.Debug || len(tc.Output) == 0 { | |||
keys := slices.Sorted(maps.Keys(result)) | |||
|
|||
t.Log("Changed keys after migration:") | |||
if len(keys) > 0 { | |||
t.Log("Changed keys after migration:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it changed keys after migration or just keys after mgiration?
PR Type
Enhancement, Tests
Description
Introduced strict schema validation for OAS with an optional toggle.
Updated
WebhookEvent
struct to enforce stricter validation.Enhanced test coverage for schema loading and validation.
Adjusted JSON schema definitions to improve validation accuracy.
Changes walkthrough 📝
event.go
Enforce stricter validation in `WebhookEvent` struct
apidef/oas/event.go
BodyTemplate
inWebhookEvent
.CoolDownPeriod
field.validator.go
Add strict mode toggle for OAS schema loading
apidef/oas/validator.go
LoadOASSchema
with a strict mode toggle.build.sh
Update build script for strict schema generation
apidef/oas/schema/build.sh
x-tyk-api-gateway.json
Update JSON schema definitions for validation accuracy
apidef/oas/schema/x-tyk-api-gateway.json
cooldownPeriod
to referenceX-Tyk-ReadableDuration
.type
property to directly referenceX-Tyk-EventType
.x-tyk-api-gateway.strict.json
Adjust strict schema for enhanced validation
apidef/oas/schema/x-tyk-api-gateway.strict.json
additionalProperties
forX-Tyk-EventHandlers
.cooldownPeriod
to referenceX-Tyk-ReadableDuration
.fixtures_test.go
Add schema validation and logging improvements in tests
apidef/oas/fixtures_test.go
TestFixtures
.linter_test.go
Update linter test to use strict schema
apidef/oas/linter_test.go
validator_test.go
Update tests for schema loading with strict mode
apidef/oas/validator_test.go